-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathApp.java
More file actions
183 lines (155 loc) · 6.67 KB
/
App.java
File metadata and controls
183 lines (155 loc) · 6.67 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package models;
import services.SneakerService;
import java.awt.*;
import java.io.IOException;
import java.sql.SQLOutput;
import java.util.InputMismatchException;
import java.util.Scanner;
public class App {
private SneakerService sneakerService = new SneakerService(); // (1)
Scanner scanner = new Scanner(System.in);
private Sneaker sneaker = new Sneaker();
public static void main(String[] args) {
App application = new App(); // (2)
application.init(); // (3)
}//main
public void init(){
SneakerService.loadData();
Console.printWelcome();
// (4)
// application logic here
// call methods to take user input and interface with services
boolean flag = true;
while (flag) {
System.out.println(ColorEnum.CYAN.formatString("📝Main Menu"));
System.out.print(ColorEnum.BLUE.formatString("➕Create\t"));
System.out.print(ColorEnum.BLUE.formatString("📖Read\t "));
System.out.print(ColorEnum.BLUE.formatString("🖌Update\t"));
System.out.print(ColorEnum.BLUE.formatString("⌦ Delete\t"));
System.out.print(ColorEnum.BLUE.formatString("🔍Find\t"));
System.out.println(ColorEnum.BLUE.formatString("❗️Exit\t"));
String menu = scanner.next();
if(menu.equalsIgnoreCase("Create")){
add();
try {
SneakerService.savaDataToCsv();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
else if(menu.equalsIgnoreCase("Read")){
System.out.println("Please enter product ID:");
int id = scanner.nextInt();
read(id);
}
else if(menu.equalsIgnoreCase("Update")){
System.out.println("Please enter product id");
int id = scanner.nextInt();
update(id);
}
else if(menu.equalsIgnoreCase("Delete")){
System.out.println("Please enter product id");
int id = scanner.nextInt();
sneaker.delete(id);
}
else if(menu.equalsIgnoreCase("Find")){
System.out.println("Please enter product id");
int id = scanner.nextInt();
Sneaker sneaker1 = sneaker.findSneaker(id);
if(sneaker1!=null){
System.out.println(sneaker1.toString());
}
}
else if(menu.equalsIgnoreCase("exit")){
break;
}
}
}
/**Create different products to be added to inventory
Read from existing products
Update products
Delete products
Get different reports about products
Exit the program*/
public void add(){
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter product name:");
String name = scanner.nextLine();
System.out.println("Please enter brand name:");
String brand = scanner.nextLine();
System.out.println("Please enter sport name:");
String sport = scanner.nextLine();
System.out.println("Please enter product size:");
float size = scanner.nextFloat();
System.out.println("Please enter product quantity:");
int qty = scanner.nextInt();
System.out.println("Please enter product price:");
float price = scanner.nextFloat();
sneaker = SneakerService.create(name,brand,sport,size,qty,price);
System.out.println("Product created and product ID: " + sneaker.getId());
}
public void update(int id){
for (Sneaker s:SneakerService.getInventory()){
if(s.getId() == id){
System.out.println("Please choice valid option");
System.out.println(ColorEnum.CYAN.formatString("📝Options"));
System.out.print(ColorEnum.BLUE.formatString("Name\t"));
System.out.print(ColorEnum.BLUE.formatString("Brand\t "));
System.out.print(ColorEnum.BLUE.formatString("Sport\t"));
System.out.print(ColorEnum.BLUE.formatString("Size\t"));
System.out.println(ColorEnum.BLUE.formatString("Quantity\t"));
System.out.println(ColorEnum.BLUE.formatString("Price\t"));
String menu1 = scanner.next();
if(menu1.equalsIgnoreCase("name")){
System.out.println("Please enter new Product name:");
String input = scanner.next();
s.setName(input);
System.out.println("Name updated to: "+s.getName());
}
else if(menu1.equalsIgnoreCase("brand")){
System.out.println("Please enter new Brand name:");
String input = scanner.next();
s.setBrand(input);
System.out.println("Brand updated to: "+s.getBrand());
}
else if(menu1.equalsIgnoreCase("sport")){
System.out.println("Please enter new Sport name:");
String input = scanner.next();
s.setSport(input);
System.out.println("Sport name updated to "+s.getSport());
}
else if(menu1.equalsIgnoreCase("size")){
System.out.println("Please enter new size:");
float input = scanner.nextFloat();
s.setSize(input);
System.out.println("Size updated to "+s.getSize());
}
else if(menu1.equalsIgnoreCase("quantity")){
System.out.println("Please enter new size:");
int input = scanner.nextInt();
s.setSize(input);
System.out.println("Quantity updated to "+s.getId());
}
else if(menu1.equalsIgnoreCase("price")){
System.out.println("Please enter new size:");
int input = scanner.nextInt();
s.setSize(input);
System.out.println("Price updated to "+ s.getPrice());
}
}
}
}
public void read(int id){
boolean flag = true;
for (Sneaker s:SneakerService.getInventory()){
if(s.getId() == id){
System.out.println(s.toString());
flag = false;
break;
}
}
if(flag) {
System.out.println(ColorEnum.RED.formatString("Product not found in the inventory!"));
}
}
}//class