-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestock.java
More file actions
99 lines (84 loc) · 2.55 KB
/
Restock.java
File metadata and controls
99 lines (84 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.util.*;
public class Restock
{
static void restock()
{
Scanner in = new Scanner(System.in);
Inventory inv = Inventory.getInstance();
char action;
System.out.println(inv);
while(true)
{
System.out.println("(S)can/(N)ew Item/(E)nd");
action = in.nextLine().charAt(0);
action = Character.toUpperCase(action);
switch (action)
{
case 'S':
scanItem();
break;
case 'N':
newItem();
System.out.println("New item added");
break;
case 'E':
return;
default:
System.out.println("Choice not valid, please try again.");
}
}
}
private static void scanItem()
{
Scanner stdin = new Scanner(System.in);
Inventory inv = Inventory.getInstance();
int item, amount;
while (true)
{
try
{
System.out.print("What item to scan: ");
item = Helpers.extractInt(stdin.nextLine(), inv.names.size());
if (inv.getItemName(item - 1).length() != 0 )
{
try
{
System.out.print("How many you want to add: ");
amount = stdin.nextInt();
stdin.nextLine();
inv.amounts.set(item - 1, inv.getItemAmount(item - 1) + amount);
return;
}
catch (IndexOutOfBoundsException e)
{
continue;
}
}
System.out.println("Not valid item");
}
catch (IndexOutOfBoundsException e)
{
continue;
}
}
}
private static void newItem()
{
Scanner stdin = new Scanner(System.in);
Inventory inv = Inventory.getInstance();
String name;
int quantity;
float price;
System.out.print("Name of new item: ");
name = stdin.nextLine();
System.out.print("How many to add: ");
quantity = stdin.nextInt();
stdin.nextLine();
System.out.print("Price of item: ");
price = stdin.nextFloat();
stdin.nextLine();
inv.names.add(name);
inv.amounts.add(quantity);
inv.prices.add(price);
}
}