#32 Inheritance-ProductManager

Aperto
WMartinez44 vorrebbe unire 4 commit da WMartinez44/CR-MesoLabs-Inheritance-ProductManager:master a master

+ 2
- 0
.idea/compiler.xml Vedi File

@@ -7,10 +7,12 @@
7 7
         <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8 8
         <outputRelativeToContentRoot value="true" />
9 9
         <module name="bankaccountlab" />
10
+        <module name="productmanager" />
10 11
       </profile>
11 12
     </annotationProcessing>
12 13
     <bytecodeTargetLevel target="1.8">
13 14
       <module name="bankaccountlab" target="1.5" />
15
+      <module name="productmanager" target="1.5" />
14 16
     </bytecodeTargetLevel>
15 17
   </component>
16 18
 </project>

+ 11
- 0
.idea/dataSources.local.xml Vedi File

@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="dataSourceStorageLocal">
4
+    <data-source name="@localhost" uuid="b4281651-5584-4797-b6ef-ea3d71667b9f">
5
+      <database-info product="" version="" jdbc-version="" driver-name="" driver-version="" family="MYSQL" exact-version="0.0" />
6
+      <secret-storage>master_key</secret-storage>
7
+      <first-sync>true</first-sync>
8
+      <user-name>root</user-name>
9
+    </data-source>
10
+  </component>
11
+</project>

+ 19
- 0
.idea/dataSources.xml Vedi File

@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
4
+    <data-source source="LOCAL" name="@localhost" uuid="b4281651-5584-4797-b6ef-ea3d71667b9f">
5
+      <driver-ref>mysql</driver-ref>
6
+      <synchronize>true</synchronize>
7
+      <jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
8
+      <jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
9
+      <driver-properties>
10
+        <property name="autoReconnect" value="true" />
11
+        <property name="zeroDateTimeBehavior" value="convertToNull" />
12
+        <property name="tinyInt1isBit" value="false" />
13
+        <property name="characterEncoding" value="utf8" />
14
+        <property name="characterSetResults" value="utf8" />
15
+        <property name="yearIsDateType" value="false" />
16
+      </driver-properties>
17
+    </data-source>
18
+  </component>
19
+</project>

+ 13
- 0
.idea/libraries/Maven__junit_junit_4_12.xml Vedi File

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: junit:junit:4.12">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml Vedi File

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: org.hamcrest:hamcrest-core:1.3">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 1
- 1
.idea/modules.xml Vedi File

@@ -2,7 +2,7 @@
2 2
 <project version="4">
3 3
   <component name="ProjectModuleManager">
4 4
     <modules>
5
-      <module fileurl="file://$PROJECT_DIR$/bankaccountlab.iml" filepath="$PROJECT_DIR$/bankaccountlab.iml" />
5
+      <module fileurl="file://$PROJECT_DIR$/productmanager.iml" filepath="$PROJECT_DIR$/productmanager.iml" />
6 6
     </modules>
7 7
   </component>
8 8
 </project>

+ 543
- 388
.idea/workspace.xml
File diff suppressed because it is too large
Vedi File


+ 10
- 0
pom.xml Vedi File

@@ -8,5 +8,15 @@
8 8
     <artifactId>productmanager</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <dependencies>
12
+        <dependency>
13
+            <groupId>junit</groupId>
14
+            <artifactId>junit</artifactId>
15
+            <version>4.12</version>
16
+            <scope>test</scope>
17
+        </dependency>
18
+    </dependencies>
19
+
20
+
11 21
 
12 22
 </project>

+ 129
- 0
src/main/java/com/zipcodewilmington/productmanager/MainApplication.java Vedi File

@@ -1,7 +1,136 @@
1 1
 package com.zipcodewilmington.productmanager;
2 2
 
3
+import sun.applet.Main;
4
+
5
+import java.text.DecimalFormat;
6
+import java.util.Scanner;
7
+
3 8
 /**
4 9
  * Created by leon on 1/10/18.
10
+ * In your main class initialize your manager and populate your inventory
11
+ * Demonstrate calling methods on your manager
12
+ * Print all output to screen
5 13
  */
14
+
6 15
 public class MainApplication {
16
+
17
+
18
+    public static void main(String[] args) {
19
+
20
+
21
+        MainApplication main = new MainApplication();
22
+        Scanner scan;
23
+
24
+        scan = new Scanner(System.in);
25
+
26
+
27
+        Product[] products = new Product[4];
28
+
29
+        products[0] = new Product(2.3, 1, 03, "a pair of socks");
30
+
31
+
32
+        products[1] = new Product(12.3, 2, 02, "hat");
33
+
34
+        products[2] = new Product(35.00, 3, 01, "button up shirt");
35
+
36
+        products[3] = new Product(16.00, 8, 04, "Glasses");
37
+
38
+
39
+        System.out.println("What kind of clothes do you want? \n");
40
+        for (int i = 0; i < products.length; i++) {
41
+
42
+            System.out.println(i + " Here are the selections: " + products[i].getDescription());
43
+
44
+        }
45
+        DecimalFormat df = new DecimalFormat("#.00");
46
+        double counter = 0;
47
+        int counter2 = 0;
48
+//
49
+
50
+     loop: while (scan.hasNextInt()) {
51
+         int options = scan.nextInt();
52
+
53
+        switch (options) {
54
+            case -1:
55
+                System.out.print("You've spent $"+ df.format(counter));
56
+                break loop;
57
+
58
+            case 0:
59
+
60
+                System.out.println (products[0].getDescription());
61
+
62
+                counter += products[0].getPrice();
63
+
64
+                System.out.println("You know that socks are like cotton bags for your feet?\n");
65
+
66
+//
67
+
68
+                    break;
69
+
70
+
71
+            case 1:
72
+
73
+                System.out.println (products[1].getDescription());
74
+                counter += products[1].getPrice();
75
+                System.out.println("What kind of hat? Who knows! Maybe its a ten gallon one. Or a witch hat.");
76
+//                x1-=x1;
77
+//
78
+
79
+//                if(x1< 0){
80
+//
81
+//                    System.out.println("WE RAN OUT! TRY SOMETHING ELSE!");
82
+//
83
+//                }else{
84
+//
85
+//                    System.out.println("What kind of hat? Who knows! Maybe its a ten gallon one. Or a witch hat.");
86
+//                }
87
+                break;
88
+
89
+            case 2:
90
+                System.out.println (products[2].getDescription());
91
+                System.out.println("I'll be honest with you, it's a tacky hawaiian shirt but I totally think you can pull it off, at a job interview");
92
+                counter += products[2].getPrice();
93
+
94
+//                x2-=x2;
95
+//
96
+//                if(x2 < 0){
97
+//
98
+//                    System.out.println("WE RAN OUT! TRY SOMETHING ELSE!");
99
+//                    break;
100
+//
101
+//                }else{
102
+//
103
+//                    System.out.println("I'll be honest with you, it's a tacky hawaiian shirt but I totally think you can pull it off, at a job interview");
104
+//                }
105
+
106
+                break;
107
+
108
+            case 3:
109
+                System.out.println (products[3].getDescription());
110
+                System.out.println("Sweet shades bro \uD83D\uDE0E");
111
+                counter += products[3].getPrice();
112
+
113
+//                x3-=x3;
114
+//                if(x3 < 0){
115
+//
116
+//                    System.out.println("WE RAN OUT! TRY SOMETHING ELSE!");
117
+//
118
+//                }else{
119
+//
120
+//                    System.out.println("Sweet shades bro \uD83D\uDE0E");
121
+//                }
122
+                break;
123
+
124
+            default:
125
+                System.out.println("Out of Stock, my dude but I'll let you know when we got it again \uD83D\uDE09 ");
126
+                counter2 ++;
127
+                if (counter2 >= 3){
128
+                    System.out.println("Look, if you're just gonna keep bugging me about this maybe you should go.");
129
+                    System.out.print("You've spent $"+ df.format(counter));
130
+                    break loop;
131
+
132
+            }
133
+        }
134
+    }
135
+}
7 136
 }

+ 44
- 0
src/main/java/com/zipcodewilmington/productmanager/Manager.java Vedi File

@@ -0,0 +1,44 @@
1
+package com.zipcodewilmington.productmanager;
2
+
3
+import java.util.ArrayList;
4
+
5
+public class Manager {
6
+
7
+    private ArrayList<Product> storeStuff;
8
+
9
+
10
+    public Manager(){
11
+
12
+        this.storeStuff = new ArrayList<Product>();
13
+        String name;
14
+        int quantity;
15
+        int id;
16
+        double price;
17
+
18
+
19
+
20
+
21
+    }
22
+
23
+    public void addingProducts(Product product) {
24
+            storeStuff.add(product);
25
+
26
+
27
+    }
28
+
29
+
30
+    public void removing_stuff(Product product){
31
+
32
+            storeStuff.remove(product);
33
+    }
34
+
35
+    public int size (){
36
+
37
+       return storeStuff.size();
38
+
39
+    }
40
+
41
+
42
+
43
+
44
+}

+ 10
- 0
src/main/java/com/zipcodewilmington/productmanager/Market.java Vedi File

@@ -0,0 +1,10 @@
1
+package com.zipcodewilmington.productmanager;
2
+
3
+import java.util.ArrayList;
4
+
5
+public class Market {
6
+
7
+
8
+
9
+
10
+}

+ 71
- 1
src/main/java/com/zipcodewilmington/productmanager/Product.java Vedi File

@@ -3,5 +3,75 @@ package com.zipcodewilmington.productmanager;
3 3
 /**
4 4
  * Created by leon on 1/10/18.
5 5
  */
6
-public class Product {
6
+public class Product extends Manager {
7
+
8
+
9
+    private double price;
10
+    private int quantity;
11
+    private int id;
12
+    private String name;
13
+
14
+    public Product (double price, int quantity,int id, String name){
15
+        this.price = price;
16
+        this.quantity=quantity;
17
+        this.id = id;
18
+        this.name = name;
19
+    }
20
+
21
+
22
+    public double getPrice()
23
+    {
24
+
25
+        return price;
26
+    }
27
+
28
+    public int getQuantity() {
29
+
30
+        return quantity;
31
+    }
32
+
33
+    public int getId() {
34
+
35
+        return id;
36
+    }
37
+
38
+    public void setId(int id) {
39
+
40
+        this.id = id;
41
+    }
42
+
43
+    public void setquantity(int quantity){
44
+
45
+
46
+        this.quantity =quantity;
47
+
48
+    }
49
+
50
+    public void setPrice(double price) {
51
+        this.price = price;
52
+
53
+    }
54
+
55
+    public void setQuantity(int quantity) {
56
+
57
+        this.quantity = quantity;
58
+    }
59
+
60
+    public String getName() {
61
+        return name;
62
+    }
63
+
64
+    public void setName(String name) {
65
+
66
+        this.name = name;
67
+    }
68
+    public String getDescription() {
69
+
70
+
71
+        String x ="This is a "+ name + " It costs $" + price +"0" ;
72
+
73
+
74
+        return x;
75
+
76
+}
7 77
 }

+ 51
- 0
src/test/java/com/zipcodewilmington/productmanager/ManagerTest.java Vedi File

@@ -0,0 +1,51 @@
1
+package com.zipcodewilmington.productmanager;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class ManagerTest {
7
+
8
+   Manager manager = new Manager();
9
+   Product product = new Product(0,0,0,"");
10
+
11
+
12
+
13
+
14
+    @Test
15
+    public void changingtheprice_test(){
16
+
17
+        product = new Product (3.42,5,01,"Soap");
18
+        product.setPrice(3.22);
19
+        Assert.assertEquals(3.22,product.getPrice(),0.01);
20
+
21
+
22
+
23
+    }
24
+    @Test
25
+    public void testRemoving() {
26
+        //Given
27
+        Manager manager = new Manager();
28
+        Product product = new Product(32.43, 2, 0003, "toy car");
29
+        Product product2 = new Product(0, 0, 0, "");
30
+        Product product1 = new Product(34.34, 1, 0004, "Pants");
31
+
32
+        //when
33
+
34
+        manager.addingProducts(product);
35
+        manager.addingProducts(product1);
36
+        manager.addingProducts(product2);
37
+        manager.removing_stuff(product1);
38
+
39
+        //Then
40
+
41
+        int ssert = manager.size();
42
+        int expect = 2;
43
+
44
+        Assert.assertEquals(ssert, expect);
45
+
46
+
47
+    }
48
+
49
+
50
+
51
+}

+ 73
- 0
src/test/java/com/zipcodewilmington/productmanager/ProductTest.java Vedi File

@@ -1,7 +1,80 @@
1 1
 package com.zipcodewilmington.productmanager;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import java.util.ArrayList;
7
+
3 8
 /**
4 9
  * Created by leon on 1/10/18.
5 10
  */
6 11
 public class ProductTest {
12
+
13
+    @Test
14
+    public void testGetSetPrice(){
15
+        Product product = new Product(3.45,4,02,"coke");
16
+        double price = 23.99;
17
+
18
+
19
+        product.setPrice(price);
20
+        double actualPrice = product.getPrice();
21
+
22
+        Assert.assertEquals(price, actualPrice, 0.001);
23
+
24
+
25
+    }
26
+    @Test
27
+    public void testGetQuantity(){
28
+        Product product = new Product(33.27,20,03,"table");
29
+        int quantity = 4;
30
+
31
+        product.setquantity(quantity);
32
+        int actualQuantity = product.getQuantity();
33
+
34
+        Assert.assertEquals (quantity,actualQuantity);
35
+
36
+    }
37
+    @Test
38
+    public void testGetID(){
39
+        Product product = new Product(32.43, 2,0003,"toy car");
40
+        int Id = 449424;
41
+
42
+        product.setId(Id);
43
+        int actualid = product.getId();
44
+
45
+        Assert.assertEquals (Id,actualid);
46
+
47
+    }
48
+    @Test
49
+    public void getting_Initial_Price(){
50
+
51
+        Product product = new Product (3.42,5,01,"Soap");
52
+        Manager manager = new Manager();
53
+
54
+
55
+        double expected = 3.42;
56
+        double actual = product.getPrice();
57
+
58
+        Assert.assertEquals(expected,actual,0.01);
59
+
60
+
61
+    }
62
+
63
+    @Test
64
+    public void QuantityTest(){
65
+
66
+        Product product = new Product(0,0,0,"");
67
+
68
+
69
+        product.setquantity(5);
70
+        int actual =  product.getQuantity();
71
+        int expect = 5;
72
+
73
+        Assert.assertEquals(actual,expect);
74
+
75
+    }
76
+
77
+
78
+
79
+
7 80
 }