-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.java
89 lines (76 loc) · 2.02 KB
/
order.java
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
import java.util.*;
public class order{
static int temp=1001;
int oid;
int bid;
int cid;
public order()
{
}
public order(int bid,int cid)
{
this.oid=temp++;
this.bid=bid;
this.cid=cid;
}
static Map<Integer,Customer> cc = new HashMap<>();
static Map<Integer,book> bb = new HashMap<>();
static Map<Integer,order> oo = new HashMap<>();
LinkedList<Integer> orders = new LinkedList<>();
public void storeBooks(book b,int id)
{
bb.put(id,b);
}
public void display()
{
for(book b : bb.values())
{
System.out.println("---------------------------------");
System.out.println("Book id : "+b.bid);
System.out.println("Book name : "+b.name);
System.out.println("Book price : "+b.price);
System.out.println("Book status : "+b.status);
System.out.println("---------------------------------");
}
}
public void buy(int bid,Customer c)
{
try{
book bk = bb.get(bid);
if(bk.status.equals("available"))
{
cc.put(c.id,c);
order o = new order(bid,c.id);
oo.put(o.oid,o);
orders.add(1);
bk.status="Not available";
System.out.println("Book purchases successfully :)\n");
}
else{
System.out.println("Book not available :(\n");
}
}
catch(Exception e)
{
System.out.println("enter correct book id !\n");
}
}
public void displayOrder(){
for(order b : oo.values())
{
System.out.println("---------------------------------");
System.out.println("order id : "+b.oid);
Customer c = cc.get(b.cid);
System.out.println("---------------------------------");
System.out.println("customer id : "+c.id);
System.out.println("customer name : "+c.name);
System.out.println("customer : "+c.age);
System.out.println("---------------------------------");
book b1 = bb.get(b.bid);
System.out.println("Book id : "+b1.bid);
System.out.println("Book name : "+b1.name);
System.out.println("Book price : "+b1.price);
System.out.println("---------------------------------");
}
}
}