-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE_Shop.java
More file actions
323 lines (264 loc) · 7.15 KB
/
E_Shop.java
File metadata and controls
323 lines (264 loc) · 7.15 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import java.io.*;
import java.util.*;
public class E_Shop implements Serializable
{
static String pro;
//shop variables
private String name;
private int price;
private int rate;
private int id;
static int x;
//bill variables
private String dealer;
private String product;
private int cost;
private int quant=0;
private int total=0;
//shop functions
public void setName(String name)
{
this.name=name;
}
public void setPrice(int price)
{
this.price=price;
}
public void setRate(int rate)
{
this.rate=rate;
}
public void setID(int id)
{
this.id=id;
}
public int getID()
{
return id;
}
public String getName()
{
return name;
}
public int getPrice()
{
return price;
}
public int getRate()
{
return rate;
}
//bill functions
public void setDeal(String dealer)
{
this.dealer=dealer;
}
public void setProd(String product)
{
this.product=product;
}
public void setCost(int cost)
{
this.cost=cost;
}
public String getDeal()
{
return dealer;
}
public String getProd()
{
return product;
}
public int getCost()
{
return cost;
}
/*public int getQuant()
{
return quant;
}
public int getTotal()
{
int a = quant*price;
return a;
}*/
//main function
public static void main (String[] args) throws IOException , Exception
{
//shop objects
E_Shop obj1 = new E_Shop();
obj1.setName("Mobile 1");
obj1.setPrice(12999);
obj1.setRate(4);
obj1.setID(1);
E_Shop obj2 = new E_Shop();
obj2.setName("Mobile 2");
obj2.setPrice(90000);
obj2.setRate(2);
obj2.setID(2);
E_Shop obj3 = new E_Shop();
obj3.setName("Mobile 3");
obj3.setPrice(13000);
obj3.setRate(4);
obj3.setID(3);
E_Shop obj4 = new E_Shop();
obj4.setName("Mobile 4");
obj4.setPrice(13999);
obj4.setRate(3);
obj4.setID(4);
E_Shop obj5 = new E_Shop();
obj5.setName("Mobile 5");
obj5.setPrice(18000);
obj5.setRate(4);
obj5.setID(5);
E_Shop obj6 = new E_Shop();
obj6.setName("Mobile 6");
obj6.setPrice(25999);
obj6.setRate(4);
obj6.setID(6);
//bill objects
Bill o1 = new Bill();
o1.setDeal("Dealer 1");
o1.setProd("Mobile 1");
o1.setCost(12999);
Bill o2 = new Bill();
o2.setDeal("Dealer 2");
o2.setProd("Mobile 2");
o2.setCost(90000);
Bill o3 = new Bill();
o3.setDeal("Dealer 3");
o3.setProd("Mobile 3");
o3.setCost(13000);
Bill o4 = new Bill();
o4.setDeal("Dealer 4");
o4.setProd("Mobile 4");
o4.setCost(13999);
Bill o5 = new Bill();
o5.setDeal("Dealer 5");
o5.setProd("Mobile 5");
o5.setCost(18000);
Bill o6 = new Bill();
o6.setDeal("Dealer 6");
o6.setProd("Mobile 6");
o6.setCost(25999);
//shop file
File f = new File("obj.txt");
FileOutputStream fos_obj = new FileOutputStream(f);
ObjectOutputStream oos_obj = new ObjectOutputStream(fos_obj);
oos_obj.writeObject(obj1);
oos_obj.writeObject(obj2);
oos_obj.writeObject(obj3);
oos_obj.writeObject(obj4);
oos_obj.writeObject(obj5);
oos_obj.writeObject(obj6);
oos_obj.close();
fos_obj.close();
FileInputStream fis_obj = new FileInputStream(f);
ObjectInputStream ois_obj = new ObjectInputStream(fis_obj);
int i = 1;
System.out.println();
System.out.println("---------------------------------------------------------------------");
System.out.println(" WELCOME TO E_MARKET ");
System.out.println("---------------------------------------------------------------------");
System.out.println();
System.out.println(" "+"Sr."+" "+" Mobile" + " " + " Rate"+ " "+" Price");
System.out.println();
File f_1 = new File("obj.txt");
FileInputStream fis_obj_1 = new FileInputStream(f_1);
ObjectInputStream ois_obj_1 = new ObjectInputStream(fis_obj_1);
int m=1;
try
{
while(true)
{
E_Shop s = ((E_Shop)ois_obj.readObject());
System.out.print(" "+s.getID() + " ");
System.out.print(s.getName() + " ");
System.out.print(s.getRate() + " ");
System.out.println(s.getPrice() + " ");
//E_Shop s = ((E_Shop)ois_obj.readObject());
}
}
catch(Exception e)
{
System.out.println();
Scanner sc = new Scanner(System.in);
System.out.println("<------------------CHOOSE YOUR PRODUCT----------------------------->");
System.out.println("");
System.out.print(" "+"Select a Product : ");
int n=sc.nextInt();
System.out.println("");
System.out.println("<-----------------------QUANTITY----------------------------------->");
System.out.println();
System.out.print(" "+"Enter the Quantity : ");
x=sc.nextInt();
for(int var=0;var<10;var++)
{
System.out.println("");
}
System.out.println("--------------------------------------------------------------------");
System.out.println(" BILL ");
System.out.println("--------------------------------------------------------------------");
while(n!=m)
{
ois_obj_1.readObject();
m++;
}
}
E_Shop s = (E_Shop)ois_obj_1.readObject();
pro = s.getName();
//System.out.println(pro);
fis_obj_1.close();
//bill file
File f1 = new File("obj1.txt");
FileOutputStream fos_obj1 = new FileOutputStream(f1);
ObjectOutputStream oos_obj1 = new ObjectOutputStream(fos_obj1);
oos_obj1.writeObject(o1);
oos_obj1.writeObject(o2);
oos_obj1.writeObject(o3);
oos_obj1.writeObject(o4);
oos_obj1.writeObject(o5);
oos_obj1.writeObject(o6);
oos_obj1.close();
fos_obj1.close();
FileInputStream fis_obj1 = new FileInputStream(f1);
ObjectInputStream ois_obj1 = new ObjectInputStream(fis_obj1);
Bill b = (Bill)ois_obj1.readObject();
int j = 1;
System.out.println();
System.out.println();
System.out.println(" "+"E_SHOP NAME : Invoice Tel Pvt. Ltd.");
System.out.println(" "+"ADDRESS : SCO 315, SECOND FLOOR, SECTOR 40 D, CHANDIGARH ");
System.out.println(" "+"WARRANTY : 1 YEAR");
System.out.println(" "+"CONTACT NO. : 9564712354");
System.out.println(" "+"EMAIL_ID : invoicetel@gmail.com");
System.out.println();
System.out.println();
System.out.println(" "+"Dealer"+" "+"Product" + " " + "Price"+ " " + "Quantity"+" "+"Total");
System.out.println("---------------------------------------------------------------------");
String d;
try
{
while(true)
{
d = b.getProd();
//System.out.println(d+" "+pro);
if(d.equals(pro))
{
System.out.print(" "+b.getDeal() + " ");
System.out.print(b.getProd() + " ");
System.out.print(b.getCost() + " ");
System.out.print(x + " ");
System.out.println(x*b.getCost() + " ");
System.out.println("---------------------------------------------------------------------");
System.out.println();
System.out.println(" "+"GRAND TOTAL : "+ x*b.getCost());
System.out.println();
}
b = ((Bill)ois_obj1.readObject());
}
}
catch(Exception e)
{}
}
}