Kaynağa Gözat

inheritance

BlackJack 6 yıl önce
ebeveyn
işleme
74cc9506e2

+ 9
- 0
.idea/ZCW-MesoLabs-Inheritance-ProductManager-BlueJ.iml Dosyayı Görüntüle

@@ -0,0 +1,9 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+    <exclude-output />
5
+    <content url="file://$MODULE_DIR$" />
6
+    <orderEntry type="inheritedJdk" />
7
+    <orderEntry type="sourceFolder" forTests="false" />
8
+  </component>
9
+</module>

+ 6
- 0
.idea/misc.xml Dosyayı Görüntüle

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="JavaScriptSettings">
4
+    <option name="languageLevel" value="ES6" />
5
+  </component>
6
+</project>

+ 8
- 0
.idea/modules.xml Dosyayı Görüntüle

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/.idea/ZCW-MesoLabs-Inheritance-ProductManager-BlueJ.iml" filepath="$PROJECT_DIR$/.idea/ZCW-MesoLabs-Inheritance-ProductManager-BlueJ.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 69
- 0
.idea/workspace.xml Dosyayı Görüntüle

@@ -0,0 +1,69 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="NodePackageJsonFileManager">
4
+    <packageJsonPaths />
5
+  </component>
6
+  <component name="PropertiesComponent">
7
+    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
8
+    <property name="nodejs_npm_path_reset_for_default_project" value="true" />
9
+  </component>
10
+  <component name="RunManager">
11
+    <configuration default="true" type="Application" factoryName="Application">
12
+      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
13
+    </configuration>
14
+    <configuration default="true" type="JUnit" factoryName="JUnit">
15
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
16
+      <option name="ALTERNATIVE_JRE_PATH" />
17
+      <option name="PACKAGE_NAME" />
18
+      <option name="MAIN_CLASS_NAME" />
19
+      <option name="METHOD_NAME" />
20
+      <option name="TEST_OBJECT" value="class" />
21
+      <option name="VM_PARAMETERS" value="-ea" />
22
+      <option name="PARAMETERS" />
23
+      <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
24
+      <option name="PASS_PARENT_ENVS" value="true" />
25
+      <option name="TEST_SEARCH_SCOPE">
26
+        <value defaultName="singleModule" />
27
+      </option>
28
+      <patterns />
29
+    </configuration>
30
+    <configuration default="true" type="TestNG" factoryName="TestNG">
31
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
32
+      <option name="ALTERNATIVE_JRE_PATH" />
33
+      <option name="SUITE_NAME" />
34
+      <option name="PACKAGE_NAME" />
35
+      <option name="MAIN_CLASS_NAME" />
36
+      <option name="METHOD_NAME" />
37
+      <option name="GROUP_NAME" />
38
+      <option name="TEST_OBJECT" value="CLASS" />
39
+      <option name="VM_PARAMETERS" value="-ea" />
40
+      <option name="PARAMETERS" />
41
+      <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
42
+      <option name="OUTPUT_DIRECTORY" />
43
+      <option name="PASS_PARENT_ENVS" value="true" />
44
+      <option name="TEST_SEARCH_SCOPE">
45
+        <value defaultName="singleModule" />
46
+      </option>
47
+      <option name="USE_DEFAULT_REPORTERS" value="false" />
48
+      <option name="PROPERTIES_FILE" />
49
+      <properties />
50
+      <listeners />
51
+    </configuration>
52
+  </component>
53
+  <component name="masterDetails">
54
+    <states>
55
+      <state key="ProjectJDKs.UI">
56
+        <settings>
57
+          <last-edited>1.8</last-edited>
58
+          <splitter-proportions>
59
+            <option name="proportions">
60
+              <list>
61
+                <option value="0.2" />
62
+              </list>
63
+            </option>
64
+          </splitter-proportions>
65
+        </settings>
66
+      </state>
67
+    </states>
68
+  </component>
69
+</project>

+ 36
- 0
Inventory.java Dosyayı Görüntüle

@@ -0,0 +1,36 @@
1
+import java.util.*;
2
+/**
3
+ * Write a description of class Inventory here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Inventory
9
+{
10
+    
11
+    private List<Product> products;
12
+    
13
+    
14
+    public Inventory(){
15
+    products = new ArrayList();
16
+    }
17
+    
18
+    public void add(Product product){
19
+        products.add(product);
20
+    
21
+    }
22
+    
23
+    public List<Product> getProduct(){
24
+    return products;
25
+    }
26
+    
27
+    public int getTotalQuantity(){
28
+    int total = 0;
29
+    
30
+    for (Product p : products){
31
+    total += p.getQuantity();
32
+    
33
+    }
34
+    return total;
35
+    }
36
+}

+ 15
- 0
MainApplication.java Dosyayı Görüntüle

@@ -3,4 +3,19 @@
3 3
  * Created by leon on 1/10/18.
4 4
  */
5 5
 public class MainApplication {
6
+    
7
+    public static void main (String[] args){
8
+    Inventory inventory = new Inventory();
9
+    Product tea = new Product (1.99, 1, 10);
10
+    Product coffee = new Product(3.99, 9, 5);
11
+    
12
+    inventory.add(tea);
13
+    inventory.add(coffee);
14
+    
15
+    int Quantity = inventory.getTotalQuantity();
16
+    System.out.println("Total quantity is" + Quantity);
17
+    
18
+    }
19
+    
6 20
 }
21
+

+ 39
- 1
Product.java Dosyayı Görüntüle

@@ -1,7 +1,45 @@
1 1
 
2
-
3 2
 /**
4 3
  * Created by leon on 1/10/18.
5 4
  */
6 5
 public class Product {
6
+    private double price;
7
+    private int id;
8
+    private int quantity;
9
+public Product(){
10
+}
11
+
12
+    public Product(double price, int id, int quantity){
13
+        this.id = id;
14
+        this.price = price;
15
+        this.quantity = quantity;
16
+    }
17
+
18
+    public void setPrice(double newPrice){
19
+        this.price = newPrice;
20
+    }
21
+
22
+    public void setId(int newId){
23
+        this.id = newId;
24
+    }
25
+
26
+    public void setQuantity(int newQuantity){
27
+        this.quantity = newQuantity;
28
+    } 
29
+
30
+    public double getPrice(){
31
+        return price;
32
+    }
33
+
34
+    public int getId(){
35
+        return id;
36
+    }
37
+
38
+    public int getQuantity(){
39
+        return quantity;
40
+    }
41
+
42
+    public String toString(){
43
+        return Integer.toString(id) + " - " + price + " - " + quantity;
44
+    }
7 45
 }

+ 83
- 2
ProductTest.java Dosyayı Görüntüle

@@ -1,5 +1,86 @@
1
+
2
+import static org.junit.Assert.*;
3
+import org.junit.After;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
1 7
 /**
2
- * Created by leon on 1/10/18.
8
+ * The test class ProductTest.
9
+ *
10
+ * @author  (your name)
11
+ * @version (a version number or a date)
3 12
  */
4
-public class ProductTest {
13
+public class ProductTest
14
+{
15
+    /**
16
+     * Default constructor for test class ProductTest
17
+     */
18
+    @Test
19
+    public void  testEmptyConstructor()
20
+    {
21
+        Product product = new Product();
22
+    }
23
+
24
+    /**
25
+     * Sets up the test fixture.
26
+     *
27
+     * Called before every test case method.
28
+     */
29
+    @Before
30
+    public void setUp()
31
+    {
32
+    }
33
+
34
+    /**
35
+     * Tears down the test fixture.
36
+     *
37
+     * Called after every test case method.
38
+     */
39
+    @After
40
+    public void tearDown()
41
+    {
42
+    }
43
+
44
+    @Test
45
+    public void testConsWithIdPriceQuantity(){
46
+        int id = 19;
47
+        double price = 12.00;
48
+        int quantity = 7;
49
+
50
+        Product newProduct = new Product(price, id, quantity);
51
+
52
+    }
53
+
54
+    @Test
55
+    public void testGetSetPrice(){
56
+        Product product = new Product();
57
+        double price = 89.99;
58
+
59
+        product.setPrice(price);
60
+        double actualPrice = product.getPrice();
61
+
62
+        assertEquals(price, actualPrice, 0.01);
63
+
64
+    }
65
+    @Test
66
+    public void testGetSetID(){
67
+        Product product = new Product();
68
+        int ID = 101;
69
+
70
+        product.setId(ID);
71
+        int actualID = product.getId();
72
+
73
+        assertEquals(ID, actualID);
74
+
75
+    }
76
+    @Test
77
+    public void testGetSetQuantity(){
78
+        Product product = new Product();
79
+        int Quantity = 5;
80
+
81
+        product.setQuantity(Quantity);
82
+        int actualQuantity = product.getQuantity();
83
+
84
+        assertEquals(Quantity, actualQuantity);
85
+    }
5 86
 }

+ 49
- 8
package.bluej Dosyayı Görüntüle

@@ -1,20 +1,32 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+dependency1.from=Inventory
3
+dependency1.to=Product
4
+dependency1.type=UsesDependency
5
+dependency2.from=MainApplication
6
+dependency2.to=Inventory
7
+dependency2.type=UsesDependency
8
+dependency3.from=MainApplication
9
+dependency3.to=Product
10
+dependency3.type=UsesDependency
11
+dependency4.from=ProductTest
12
+dependency4.to=Product
13
+dependency4.type=UsesDependency
14
+editor.fx.0.height=716
3 15
 editor.fx.0.width=800
4
-editor.fx.0.x=560
5
-editor.fx.0.y=117
16
+editor.fx.0.x=695
17
+editor.fx.0.y=-956
6 18
 objectbench.height=101
7
-objectbench.width=461
19
+objectbench.width=776
8 20
 package.divider.horizontal=0.6
9 21
 package.divider.vertical=0.8007380073800738
10 22
 package.editor.height=427
11 23
 package.editor.width=674
12
-package.editor.x=141
13
-package.editor.y=59
24
+package.editor.x=17
25
+package.editor.y=50
14 26
 package.frame.height=600
15 27
 package.frame.width=800
16
-package.numDependencies=0
17
-package.numTargets=0
28
+package.numDependencies=4
29
+package.numTargets=4
18 30
 package.showExtends=true
19 31
 package.showUses=true
20 32
 project.charset=UTF-8
@@ -23,3 +35,32 @@ readme.name=@README
23 35
 readme.width=47
24 36
 readme.x=10
25 37
 readme.y=10
38
+target1.height=50
39
+target1.name=ProductTest
40
+target1.showInterface=false
41
+target1.type=UnitTestTargetJunit4
42
+target1.width=80
43
+target1.x=430
44
+target1.y=50
45
+target2.association=ProductTest
46
+target2.height=50
47
+target2.name=Product
48
+target2.showInterface=false
49
+target2.type=ClassTarget
50
+target2.width=80
51
+target2.x=400
52
+target2.y=80
53
+target3.height=50
54
+target3.name=Inventory
55
+target3.showInterface=false
56
+target3.type=ClassTarget
57
+target3.width=80
58
+target3.x=490
59
+target3.y=260
60
+target4.height=50
61
+target4.name=MainApplication
62
+target4.showInterface=false
63
+target4.type=ClassTarget
64
+target4.width=120
65
+target4.x=160
66
+target4.y=70