Przeglądaj źródła

Main Application Created

Rachelle 6 lat temu
rodzic
commit
2045bfc55d
3 zmienionych plików z 27 dodań i 11 usunięć
  1. 0
    10
      InventoryTest.java
  2. 22
    1
      MainApplication.java
  3. 5
    0
      Product.java

+ 0
- 10
InventoryTest.java Wyświetl plik

@@ -4,22 +4,12 @@ import org.junit.Before;
4 4
 import org.junit.Test;
5 5
 public class InventoryTest
6 6
 {   
7
-    private static final String PRODUCT_ONE_NAME = "Lemons";
8
-    private static final String PRODUCT_TWO_NAME = "Sugar";
9
-    private static final String PRODUCT_THREE_NAME = "Water";
10
-
11 7
     private Product lemons = new Product("Lemons",5.00,570370,100);
12 8
     private Product sugar = new Product("Sugar",3.00,590371,50);
13 9
     private Product water = new Product("Water",1.00,593735,200);
14 10
     private Product[] products = {lemons, sugar, water};
15 11
     private Inventory inventory = new Inventory(products);
16 12
 
17
-    @Before
18
-    public void setUp()
19
-    {
20
-
21
-    }
22
-
23 13
     @Test
24 14
     public void getWholeInventoryValueTest(){
25 15
         double expectedSum = 850.00;

+ 22
- 1
MainApplication.java Wyświetl plik

@@ -1,6 +1,27 @@
1
-
1
+import java.util.Scanner;
2 2
 /**
3 3
  * Created by leon on 1/10/18.
4 4
  */
5 5
 public class MainApplication {
6
+    Scanner scanner = new Scanner(System.in);
7
+    Product lemons = new Product("lemon",584389);
8
+    Product sugar = new Product("sugar",590452);
9
+    Product water = new Product("water",590329);
10
+    Product[] products = {lemons, sugar, water};
11
+    Inventory inventory = new Inventory(products);
12
+
13
+    public void runManager(){
14
+        for(int i = 0; i < 3; i++){
15
+            System.out.println("Enter price, quantity of "+ products[i].getName());
16
+            double price = scanner.nextInt();
17
+            products[i].setPrice(price);
18
+            int quantity = scanner.nextInt();
19
+            products[i].setQuantity(quantity);
20
+        }
21
+
22
+        double total = inventory.getWholeInventoryValue(products);
23
+
24
+        System.out.println("Total value of your inventory: "+total);    
25
+    }
6 26
 }
27
+

+ 5
- 0
Product.java Wyświetl plik

@@ -12,6 +12,11 @@ public class Product {
12 12
         
13 13
     }
14 14
 
15
+    public Product(String name, int id){
16
+        this.id = id;
17
+        this.name = name;
18
+    }
19
+    
15 20
     public Product(String name, double price, int id, int quantity){
16 21
         this.price = price;
17 22
         this.id = id;