1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /*Built by Rachelle and Nafis
- * runAdvanced built by Nafis
- */
- import java.util.Scanner;
- import java.util.InputMismatchException;
- public class MainApplication {
- Scanner scanner = new Scanner(System.in);
- Product lemons = new Product("lemon",584389);
- Product sugar = new Product("sugar",590452);
- Product water = new Product("water",590329);
- Product[] products = {lemons, sugar, water};
- Product[] newProducts;
- Inventory inventory = new Inventory(products);
-
- public void runAdvanced(){
-
- int numProducts;
- System.out.println("How many products do you have?");
- numProducts = getNumberProds();
- System.out.println("You have " + numProducts + " product(s)!");
- newProducts = new Product[numProducts];
-
- if (numProducts > 0){
- for (int i = 0; i < numProducts; i++){
- Scanner input = new Scanner(System.in);
- System.out.println("What is product " + (i+1) + "?");
- String productName = input.next();
- System.out.println("What is it's price");
- double productPrice = input.nextDouble();
- System.out.println("What is it's ID?");
- int productID = input.nextInt();
- System.out.println("How many do you have?");
- int productQuantity = input.nextInt();
- input.close();
-
- newProducts[i] = new Product(productName, productPrice, productID, productQuantity);
-
- }
- }
-
- double total = inventory.getWholeInventoryValue(newProducts);
- StringBuilder list = new StringBuilder();
- for (Product element: newProducts){
- list.append(element.getName() + " ");
- }
- System.out.println("Total value of your inventory: "+total+"\n"
- + "Your products are: \n" + list.toString());
- }
-
- public static int getNumberProds(){
- int numberProds = 0;
- Scanner input = new Scanner(System.in);
- boolean error = true;
- do{
- try{
- numberProds = input.nextInt();
- error = false;
- } catch (InputMismatchException e){
- input.next();
- System.out.println("Error! Please type a number");
- }
- } while (error);
- if (numberProds == 0){
- return 0;
- }
-
- return numberProds;
- }
-
- public void runManager(){
- for(int i = 0; i < 3; i++){
- System.out.println("Enter price, quantity of "+ products[i].getName());
- double price = scanner.nextInt();
- products[i].setPrice(price);
- int quantity = scanner.nextInt();
- products[i].setQuantity(quantity);
- }
-
- double total = inventory.getWholeInventoryValue(products);
-
- System.out.println("Total value of your inventory: "+total);
-
- }
- }
-
|