David Thornley vor 6 Jahren
Ursprung
Commit
3cb0e8f614
6 geänderte Dateien mit 325 neuen und 13 gelöschten Zeilen
  1. 74
    0
      InventoryManager.java
  2. 42
    0
      InventoryManagerTest.java
  3. 41
    0
      MainApplication.java
  4. 36
    1
      Product.java
  5. 75
    0
      ProductTest.java
  6. 57
    12
      package.bluej

+ 74
- 0
InventoryManager.java Datei anzeigen

@@ -0,0 +1,74 @@
1
+
2
+/**
3
+ * Write a description of class InventoryManager here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+
9
+import java.util.ArrayList;
10
+import java.util.Scanner;
11
+public class InventoryManager
12
+{
13
+    
14
+   
15
+    ArrayList<Product> productList = new ArrayList<Product>();
16
+    /**
17
+     * Constructor for objects of class InventoryManager
18
+     */
19
+    public InventoryManager(){
20
+
21
+    }
22
+
23
+    
24
+    public void addProduct (String productId, int price, int onHand){
25
+        
26
+        Product productName = new Product(price,productId, onHand);
27
+        productList.add(productName);
28
+    }
29
+    
30
+    public void addInventory (String productId, int quantity){
31
+        if(productList.contains(productId)){
32
+        int index = productList.indexOf(productId);
33
+        productList.get(index).addOnHand(quantity);
34
+    }else System.out.println("Product Not Found!");
35
+    }   
36
+    
37
+    public void removeProduct(String productId){
38
+        int index = productList.indexOf(productId);
39
+        productList.remove(index);
40
+    }
41
+    
42
+    public void displayInventory(){
43
+    for(Product p: productList){
44
+        System.out.println(p.getId() + ":");
45
+        System.out.println("On Hand: " + p.getOnHand());
46
+        System.out.println("Price: " + p.getPrice());
47
+        System.out.println("Total Inventory Value: " + p.totalValue());
48
+    }
49
+    }
50
+    
51
+    public String getStringInput(String prompt) {
52
+        Scanner scanner = new Scanner(System.in);
53
+        System.out.println(prompt);
54
+        String userInput = scanner.nextLine();
55
+        String userInput2 = userInput.toLowerCase();
56
+        return userInput2;
57
+    }
58
+    
59
+     public  Integer getIntegerInput(String prompt) {
60
+        Scanner scannerB = new Scanner(System.in);
61
+        int b = 0;
62
+        System.out.println(prompt);
63
+        while(b == 0){
64
+        if(scannerB.hasNextInt()){
65
+        b = scannerB.nextInt();
66
+    }else{
67
+        System.out.print("Invalid input please start over\n");
68
+    }
69
+}
70
+        return b;
71
+    }
72
+    
73
+}
74
+

+ 42
- 0
InventoryManagerTest.java Datei anzeigen

@@ -0,0 +1,42 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class InventoryManagerTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class InventoryManagerTest
15
+{
16
+    /**
17
+     * Default constructor for test class InventoryManagerTest
18
+     */
19
+    public InventoryManagerTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+}

+ 41
- 0
MainApplication.java Datei anzeigen

@@ -3,4 +3,45 @@
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
+        InventoryManager system = new InventoryManager();
9
+        String temp;
10
+        int tempPrice;
11
+        int tempOnHand;
12
+        boolean onOff = true;
13
+       System.out.println("Welcome to the inventory tracker.\n");
14
+       
15
+       while(onOff = true){
16
+           switch(system.getStringInput("What Would You Like To Do?\n" + "ADD product\n" + 
17
+           "ADD INVENTORY of an existing product \n" + "DISPLAY all current products\n" + 
18
+           "REMOVE a product from the system\n" +"EXIT the system\n")){
19
+             case "add" : 
20
+                temp = system.getStringInput("What Product Are You Adding?");
21
+                tempPrice = system.getIntegerInput("What Is The Product's Price?");
22
+                tempOnHand = system.getIntegerInput("How Many Do You Have?");
23
+                system.addProduct(temp,tempPrice,tempOnHand);
24
+             break;
25
+             case "add inventory" : 
26
+                 temp = system.getStringInput("What Product Are You Adding Inventory To?");
27
+                 tempOnHand = tempOnHand = system.getIntegerInput("How Much Are You Adding?");
28
+                 system.addInventory(temp,tempOnHand);
29
+             break;
30
+             case "display" : system.displayInventory();
31
+             break;
32
+             case "remove" : 
33
+                  temp = system.getStringInput("Which Product Do You Want To Remove?");
34
+                  system.removeProduct(temp);
35
+             break;
36
+             case "exit" : onOff = false;
37
+             break;
38
+             default: System.out.println("Invalid Choice: Please Try Again");
39
+             break;
40
+            }
41
+        }
42
+        
43
+        System.out.println("Goodbye");
44
+    }
45
+    
46
+     
6 47
 }

+ 36
- 1
Product.java Datei anzeigen

@@ -1,7 +1,42 @@
1 1
 
2
-
3 2
 /**
4 3
  * Created by leon on 1/10/18.
5 4
  */
6 5
 public class Product {
6
+    //  Create a product class which has a price, id, and quantity on hand
7
+    private int price;
8
+    private String id;
9
+    private int onHand;
10
+    public Product(int startPrice, String startId, int startOnHand){
11
+        this.price = startPrice;
12
+        this.id = startId;
13
+        this.onHand = startOnHand;
14
+    }
15
+
16
+    public int getPrice() {
17
+        return this.price;   
18
+    }
19
+    
20
+    public String getId() {
21
+        return this.id;
22
+    }
23
+    
24
+    public int getOnHand() {
25
+        return this.onHand;
26
+    }
27
+    
28
+    public int changePrice(int newPrice) {
29
+        this.price = newPrice;
30
+        return price;
31
+    }
32
+    
33
+    public int addOnHand(int supply) {
34
+        this.onHand = this.onHand + supply;
35
+        return onHand;
36
+    }
37
+    
38
+    public int totalValue(){
39
+    return this.onHand * this.price;
40
+    }
41
+
7 42
 }

+ 75
- 0
ProductTest.java Datei anzeigen

@@ -1,5 +1,80 @@
1 1
 /**
2 2
  * Created by leon on 1/10/18.
3 3
  */
4
+
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
4 8
 public class ProductTest {
9
+    
10
+    @Test
11
+    public void getPriceTest(){
12
+     //Given
13
+     Product test = new Product(5, "Melon", 10);
14
+     //Then
15
+     int expected = 5;
16
+     int actual = test.getPrice();
17
+     //Assert
18
+     Assert.assertEquals(expected, actual);
19
+     
20
+    }
21
+    
22
+     @Test
23
+    public void getIdTest(){
24
+     //Given
25
+     Product test = new Product(5, "Melon", 10);
26
+     //Then
27
+     String expected = "Melon";
28
+     String actual = test.getId();
29
+     //Assert
30
+     Assert.assertEquals(expected, actual);
31
+     
32
+    }
33
+    
34
+     @Test
35
+    public void getOnHandTest(){
36
+     //Given
37
+     Product test = new Product(5, "Melon", 10);
38
+     //Then
39
+     int expected = 10;
40
+     int actual = test.getOnHand();
41
+     //Assert
42
+     Assert.assertEquals(expected, actual);
43
+     
44
+    }
45
+    
46
+      @Test
47
+    public void changePriceTest(){
48
+     //Given
49
+     Product test = new Product(5, "Melon", 10);
50
+     test.changePrice(3);
51
+     //Then
52
+     int expected = 3;
53
+     int actual = test.getPrice();
54
+     //Assert
55
+     Assert.assertEquals(expected, actual);
56
+     
57
+    }
58
+    
59
+      @Test
60
+    public void addOnHandTest(){
61
+     //Given
62
+     Product test = new Product(5, "Melon", 10);
63
+     test.addOnHand(15);
64
+     //Then
65
+     int expected = 25;
66
+     int actual = test.getOnHand();
67
+     //Assert
68
+     Assert.assertEquals(expected, actual);
69
+     
70
+    }
71
+    
72
+    @Test
73
+    public void totalValueTest(){
74
+    Product test = new Product(5, "Melon", 10);
75
+    int expected = 50;
76
+    int actual = test.totalValue();
77
+    
78
+    Assert.assertEquals(expected, actual);
79
+    }
5 80
 }

+ 57
- 12
package.bluej Datei anzeigen

@@ -1,20 +1,29 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
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
2
+dependency1.from=ProductTest
3
+dependency1.to=Product
4
+dependency1.type=UsesDependency
5
+dependency2.from=InventoryManager
6
+dependency2.to=Product
7
+dependency2.type=UsesDependency
8
+dependency3.from=MainApplication
9
+dependency3.to=InventoryManager
10
+dependency3.type=UsesDependency
11
+editor.fx.0.height=713
12
+editor.fx.0.width=1151
13
+editor.fx.0.x=129
14
+editor.fx.0.y=23
15
+objectbench.height=103
16
+objectbench.width=776
8 17
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
18
+package.divider.vertical=0.7970479704797048
19
+package.editor.height=425
11 20
 package.editor.width=674
12
-package.editor.x=141
13
-package.editor.y=59
21
+package.editor.x=7
22
+package.editor.y=27
14 23
 package.frame.height=600
15 24
 package.frame.width=800
16
-package.numDependencies=0
17
-package.numTargets=0
25
+package.numDependencies=3
26
+package.numTargets=5
18 27
 package.showExtends=true
19 28
 package.showUses=true
20 29
 project.charset=UTF-8
@@ -23,3 +32,39 @@ readme.name=@README
23 32
 readme.width=47
24 33
 readme.x=10
25 34
 readme.y=10
35
+target1.height=50
36
+target1.name=ProductTest
37
+target1.showInterface=false
38
+target1.type=UnitTestTargetJunit4
39
+target1.width=100
40
+target1.x=10
41
+target1.y=170
42
+target2.height=50
43
+target2.name=InventoryManagerTest
44
+target2.showInterface=false
45
+target2.type=UnitTestTargetJunit4
46
+target2.width=140
47
+target2.x=170
48
+target2.y=120
49
+target3.association=InventoryManagerTest
50
+target3.height=50
51
+target3.name=InventoryManager
52
+target3.showInterface=false
53
+target3.type=ClassTarget
54
+target3.width=140
55
+target3.x=140
56
+target3.y=150
57
+target4.height=50
58
+target4.name=Product
59
+target4.showInterface=false
60
+target4.type=ClassTarget
61
+target4.width=80
62
+target4.x=80
63
+target4.y=230
64
+target5.height=50
65
+target5.name=MainApplication
66
+target5.showInterface=false
67
+target5.type=ClassTarget
68
+target5.width=120
69
+target5.x=450
70
+target5.y=60