-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClothes.java
More file actions
206 lines (192 loc) · 7.2 KB
/
Clothes.java
File metadata and controls
206 lines (192 loc) · 7.2 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package product;
import java.io.*;
import java.util.Objects;
import java.util.Scanner;
import user.*;
public class Clothes extends Products implements productmanagement
{
private String type;
private String size;
private String cloth_material;
public static class trial extends Thread
{
public void run()
{
System.out.print("Showing the model wearing your desired dress :)\n");
for(int i = 0;i<10;i++)
{
System.out.print("******* Showing TRIAL *******\n");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
@Override
public void showMenu() {
Scanner sc = new Scanner(System.in);
do
{
System.out.print("Which gender's product would you like to buy\n");
System.out.print("Male\n");
System.out.print("Female\n");
String gen = sc.nextLine();
gen = gen.toLowerCase();
if(!gen.equals("male") && !gen.equals("female"))
{
System.out.print("Could not recognize gender \n");
System.out.print("choose again.....\n");
showMenu();
}
System.out.print("Choose a product\nInput the number indicated before the product\n\n");
System.out.print("1. Trousers\n");
System.out.print("2. Jeans\n");
System.out.print("3. Shirt\n");
System.out.print("4. T-Shirt\n");
String op1 = sc.nextLine();
System.out.print("What size you wear\n");
System.out.print("1. S -> Small\n");
System.out.print("2. M -> Medium\n");
System.out.print("3. L -> Large\n");
System.out.print("4. XL -> Extra Large\n");
System.out.print("ENTER YOUR CHOICE : ");
String op2 = sc.nextLine();
System.out.print("What material Would you like to wear\n");
System.out.print("1. Denim\n");
System.out.print("2. Cotton\n");
System.out.print("3. Synthetic\n");
System.out.print("ENTER YOUR CHOICE : ");
String op3 = sc.nextLine();
int data_mismatch=1;
File cloth = new File("clothes.txt");
Scanner fileRead = null;
try {
fileRead = new Scanner(cloth);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String ch1,ch2,ch3,typ,siz,mat;
float pric;
String[] data;
while(true)
{
assert fileRead != null;
if (!fileRead.hasNextLine()) break;
String s = fileRead.nextLine();
data = s.split(" ");
ch1 = data[0];
ch2 = data[1];
ch3 = data[2];
typ = data[3];
siz = data[4];
mat = data[5];
pric = Float.parseFloat(data[6]);
if(Objects.equals(ch1, op1) && Objects.equals(ch2, op2) && Objects.equals(ch3, op3))
{
type=typ;
size=siz;
price=pric;
cloth_material=mat;
data_mismatch=0;
break;
}
}
fileRead.close();
if(data_mismatch==1)
{
System.out.print("Wrong size or type selection\nRetrieving to the menu\nTry again\n");
continue;
}
System.out.print("Would you like to see a model wearing this dress??\n");
System.out.print("Press y for yes and n for no\n");
char cho = sc.next().charAt(0);
if(cho=='y')
{
trial model = new trial();
model.start();
try
{
model.join();
}
catch (Exception e)
{
System.out.println("Error in model trial");
}
}
System.out.print(type+" "+size+" "+cloth_material+" "+"Rs."+price+'\n');
System.out.print("Would you like to buy it\nEnter 1 for Yes or 2 to go back : ");
int d = sc.nextInt();
Customer obj = new Customer();
File file= new File("current_user.txt");
Scanner filer = null;
try
{
filer = new Scanner(file);
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
String us="";
assert filer != null;
if(filer.hasNext())
us=filer.next();
obj.setUsername(us);
if(d==1)
{
System.out.print("Tell the quantity : ");
setQuantity();
while(true)
{
System.out.print("Press c to add to cart\n");
System.out.print("Press a to choose again\n");
System.out.print("Press q to show bill and quit\n");
System.out.print("Press t to get cart total\n");
char u = sc.next().charAt(0);
if (u == 'c') {
try {
addToCart();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print("\nTo see your bill press b and to continue shopping Press any other key\n");
char x = sc.next().charAt(0);
if (x == 'B' || x == 'b') {
obj.show_invoice();
} else {
Catalogue show1 = new Catalogue();
show1.showCatalogue();
}
}
if (u == 'q') {
obj.show_invoice();
System.exit(1);
}
if (u == 'a') {
showMenu();
}
if (u == 't') {
obj.show_the_cart_total();
System.out.print('\n' + '\n');
}
if(u == 'c') break;
}
break;
}
else if(d==2)
{
showMenu();
}
break;
}while(true);
}
@Override
public void addToCart() throws IOException {
System.out.print("Added to cart successfully!!\n");
File output = new File("current_user.txt");
FileWriter fwrite = new FileWriter(output,true);
fwrite.write("\n"+getId()+" "+"cloth "+type+"("+size+")"+"("+cloth_material+")"+" "+getQuantity()+" "+totalPrice());
fwrite.close();
}
}