-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBooks.java
More file actions
276 lines (256 loc) · 9.85 KB
/
Books.java
File metadata and controls
276 lines (256 loc) · 9.85 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package product;
import java.io.File;
import user.*;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Objects;
import java.util.Scanner;
public class Books extends Products implements productmanagement
{
Catalogue viewCatalogue = new Catalogue();
private String language;
private String genre;
private String author;
private String ratings;
private String book_name;
public class preview extends Thread
{
public void run()
{
System.out.print("******** Showing the preview of " + book_name + " ***********" + '\n');
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print("******** Showing contents from one of the chapters ********" + "\n");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print("A very nice book to read \nRecommended by most critics\nA must buy\n\n");
}
}
public void showBookInfo()
{
System.out.print("Language: "+language+'\n');
System.out.print("Genre: "+genre+'\n');
System.out.print("Book Name: "+book_name+'\n');
System.out.print("Author: "+author+'\n');
System.out.print("Ratings: "+ratings+"/5"+'\n');
System.out.print("Price: Rs."+price+'\n');
}
@Override
public void showMenu() {
Scanner sc = new Scanner(System.in);
do
{
System.out.print("Which language book you read\n");
System.out.print("1. ENGLISH\n");
System.out.print("2. HINDI\n");
System.out.print("3. FRENCH\n");
System.out.print("4. LATIN\n");
System.out.print("5. SPANISH\n");
System.out.print("ENTER YOUR CHOICE\n");
String op1 = sc.nextLine();
System.out.print("What genre you like\n");
System.out.print("1. FANTASY\n");
System.out.print("2. BIOGRAPHY/AUTO-BIOGRAPHY\n");
System.out.print("3. ACTION and THRILLER\n");
System.out.print("4. SCIENCE-FICTION\n");
System.out.print("5. SUSPENSE(MYSTERY)\n");
System.out.print("ENTER YOUR CHOICE\n");
String op2 = sc.nextLine();
String op3="";
if(Objects.equals(op2, "1"))
{
System.out.print("Select the book\n");
System.out.print("1. Harry Potter and the Half-Blood Prince\n");
System.out.print("2. Narnia-The Witch The Wizard and the Wardrobe\n");
System.out.print("3. Alice in Wonderland\n");
System.out.print("ENTER YOUR CHOICE\n");
op3 = sc.nextLine();
// system("clear");
}
else if(Objects.equals(op2, "2"))
{
System.out.print("Select the book\n");
System.out.print("1. Playing it My Way\n");
System.out.print("2. Steve-Jobs\n");
System.out.print("3. The Story of My Life\n");
System.out.print("ENTER YOUR CHOICE\n");
op3 = sc.nextLine();
// system("clear");
}
else if(Objects.equals(op2, "3"))
{
System.out.print("Select the book\n");
System.out.print("1. HUNGER GAMES\n");
System.out.print("2. BATMAN RISES\n");
System.out.print("3. Z WARS\n");
System.out.print("ENTER YOUR CHOICE\n");
op3 = sc.nextLine();
// system("clear");
}
else if(Objects.equals(op2, "4"))
{
System.out.print("Select the book\n");
System.out.print("1. Transformers\n");
System.out.print("2. Star Wars\n");
System.out.print("3. Mandalorian\n");
System.out.print("ENTER YOUR CHOICE\n");
op3 = sc.nextLine();
// system("clear");
}
else if(Objects.equals(op2, "5"))
{
System.out.print("Select the book\n");
System.out.print("1. Sherlock\n");
System.out.print("2. Insidious\n");
System.out.print("3. lupin\n");
System.out.print("ENTER YOUR CHOICE\n");
op3 = sc.nextLine();
// system("clear");
}
String ch1,ch2,ch3,lan,gen,book_nam,aut,rat;
float pric;
int data_mismatch=1;
File book = new File("books.txt");
Scanner fileRead = null;
try {
fileRead = new Scanner(book);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
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];
lan = data[3];
gen = data[4];
book_nam = data[5];
aut = data[6];
rat = data[7];
pric = Float.parseFloat(data[8]);
if(Objects.equals(ch1, op1) && Objects.equals(ch2, op2) && Objects.equals(ch3, op3))
{
language=lan;
genre=gen;
author=aut;
book_name=book_nam;
ratings=rat;
price=pric;
data_mismatch=0;
break;
}
}
fileRead.close();
if(data_mismatch==1)
{
System.out.print("Wrong type selection\nRetrieving to the menu\nTry again\n");
continue;
}
System.out.print("Showing book info\n");
showBookInfo();
System.out.print("Would you like to see the books's preview ?\n");
System.out.print("Press y for yes and n for no\n");
char choi = sc.next().charAt(0);
// system("clear");
choi = Character.toLowerCase(choi);
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(choi=='y')
{
preview model = new preview();
model.start();
try
{
model.join();
}
catch (Exception e)
{
System.out.println("Error in model trial");
}
}
System.out.print("Would you like to buy it\nEnter 1 for Yes or 2 to go back : ");
int d = sc.nextInt();
// system("clear");
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 the cart total\n");
char u;
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);
// system("clear");
if (x == 'B' || x == 'b')
{
obj.show_invoice();
}
else
{
viewCatalogue.showCatalogue();
}
}
if (u == 'q') {
// System.out.print()+"Your total bill is: ";
obj.show_invoice();
System.exit(1);
}
if (u == 'a') {
showMenu();
}
if (u == 't') {
// System.out.print("Your bill till now is : ");
obj.show_the_cart_total();
System.out.println();
}
if(u == 'c') break;
}
}
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()+" "+"book "+book_name+" "+getQuantity()+" "+totalPrice());
fwrite.close();
}
}