Browse Source

finished lab

William Simkins 6 years ago
parent
commit
552e920223
5 changed files with 145 additions and 8 deletions
  1. 29
    0
      Inventory.java
  2. 24
    0
      MainApplication.java
  3. 34
    1
      Product.java
  4. 30
    0
      ProductTest.java
  5. 28
    7
      package.bluej

+ 29
- 0
Inventory.java View File

@@ -0,0 +1,29 @@
1
+
2
+import java.util.List;
3
+import java.util.ArrayList;
4
+
5
+public class Inventory
6
+{
7
+   
8
+    ArrayList<product> productList;
9
+
10
+    
11
+    public Inventory(ArrayList<product> productList)
12
+    {
13
+        
14
+        this.productList = productList;
15
+        
16
+    }
17
+
18
+    
19
+    public int sumUpValue()
20
+    {
21
+        int valueOfProducts = 0;
22
+        
23
+        for(product list : productList){
24
+            int result = list.getPrice() + list.getQuantity();
25
+            valueOfProducts += result;
26
+        }
27
+        return valueOfProducts;
28
+    }
29
+}

+ 24
- 0
MainApplication.java View File

@@ -1,6 +1,30 @@
1 1
 
2
+import java.util.List;
3
+import java.util.ArrayList;
4
+
2 5
 /**
3 6
  * Created by leon on 1/10/18.
4 7
  */
5 8
 public class MainApplication {
9
+    
10
+    public static void main(String[] args){
11
+        
12
+         ArrayList<product> productList = new ArrayList<product>();
13
+        
14
+        product apples = new product("apples", 20, 250);
15
+        product oranges = new product("oranges", 30, 200);
16
+        product grapes = new product("grapes", 5, 300);
17
+        
18
+        productList.add(apples);
19
+        productList.add(oranges);
20
+        productList.add(grapes);
21
+        
22
+        Inventory inventory = new Inventory(productList);
23
+        
24
+        for(product list : productList){
25
+        System.out.println("Product: " + list.getID());
26
+        
27
+    }
28
+    System.out.println("Value of our inventory: $" + inventory.sumUpValue());
29
+}
6 30
 }

+ 34
- 1
Product.java View File

@@ -3,5 +3,38 @@
3 3
 /**
4 4
  * Created by leon on 1/10/18.
5 5
  */
6
-public class Product {
6
+public class product {
7
+    public int price;
8
+    public String id;
9
+    public int quantity;
10
+    
11
+    public product(String id, int price, int quantity){
12
+        this.price = price;
13
+        this.id = id;
14
+        this.quantity = quantity;
15
+    }
16
+    
17
+    public void setPrice(int price){
18
+        this.price = price;
19
+    }
20
+    
21
+    public int getPrice(){
22
+        return price;
23
+    }
24
+    
25
+    public void setID(String id){
26
+        this.id = id;
27
+    }
28
+    
29
+    public String getID(){
30
+        return id;
31
+    }
32
+    
33
+    public void setQuantity(int quantity){
34
+        this.quantity = quantity;
35
+    }
36
+    
37
+    public int getQuantity(){
38
+        return quantity;
39
+    }
7 40
 }

+ 30
- 0
ProductTest.java View File

@@ -1,5 +1,35 @@
1
+import static org.junit.Assert.*;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
1 6
 /**
2 7
  * Created by leon on 1/10/18.
3 8
  */
4 9
 public class ProductTest {
10
+
11
+    @Test
12
+    public void testGetID(){
13
+        product productList = new product("orange", 10, 200);
14
+        String actual = "orange";
15
+        String expected = productList.getID();
16
+        assertEquals(actual, expected);
17
+    }
18
+    
19
+    @Test
20
+    public void testGetPrice(){
21
+        product productList = new product("apple", 15, 250);
22
+        int actual = 15;
23
+        int expected = productList.getPrice();
24
+        assertEquals(actual, expected);
25
+    }
26
+    
27
+    @Test
28
+    public void testGetQuantity(){
29
+        product productList = new product("grapes", 12, 150);
30
+        int actual = 150;
31
+        int expected = productList.getQuantity();
32
+        assertEquals(actual, expected);
33
+    }
34
+    
5 35
 }

+ 28
- 7
package.bluej View File

@@ -1,20 +1,20 @@
1 1
 #BlueJ package file
2 2
 editor.fx.0.height=722
3 3
 editor.fx.0.width=800
4
-editor.fx.0.x=560
5
-editor.fx.0.y=117
6
-objectbench.height=101
7
-objectbench.width=461
4
+editor.fx.0.x=480
5
+editor.fx.0.y=29
6
+objectbench.height=164
7
+objectbench.width=776
8 8
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
9
+package.divider.vertical=0.6845018450184502
10
+package.editor.height=364
11 11
 package.editor.width=674
12 12
 package.editor.x=141
13 13
 package.editor.y=59
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0
17
-package.numTargets=0
17
+package.numTargets=3
18 18
 package.showExtends=true
19 19
 package.showUses=true
20 20
 project.charset=UTF-8
@@ -23,3 +23,24 @@ readme.name=@README
23 23
 readme.width=47
24 24
 readme.x=10
25 25
 readme.y=10
26
+target1.height=50
27
+target1.name=ProductTest
28
+target1.showInterface=false
29
+target1.type=ClassTarget
30
+target1.width=100
31
+target1.x=130
32
+target1.y=10
33
+target2.height=50
34
+target2.name=product
35
+target2.showInterface=false
36
+target2.type=ClassTarget
37
+target2.width=80
38
+target2.x=70
39
+target2.y=70
40
+target3.height=50
41
+target3.name=MainApplication
42
+target3.showInterface=false
43
+target3.type=ClassTarget
44
+target3.width=120
45
+target3.x=160
46
+target3.y=70