-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShoppingcart.java
More file actions
216 lines (196 loc) · 6.72 KB
/
Copy pathShoppingcart.java
File metadata and controls
216 lines (196 loc) · 6.72 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
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
public class Shoppingcart {
private Books[] order=new Books[numOfOrders];
private Order finalOrder=new Order();
private int paymentMethod;
private boolean ifStudent;
private boolean deliverReq;
private int deliverPin;
private Date date=new Date();
private double distance=0;
private double totalPrice;
static int numOfOrders=0;
Scanner input=new Scanner(System.in);
//constructors
public Shoppingcart(){
}
public Shoppingcart(Customer newCus,Books[] newOr,int newPayM,boolean newIfStu,boolean newDelR,int newDelPin,double newTotalPrice){
}
//getters
public Books[] getOrder(){
return order;}
public Books getOrderObj(int x){
return order[x];
}
public Order getFinalOrder(){
return finalOrder;
}
public int getPaymentMethod(){
return paymentMethod;
}
public double getTotalPrice(){
return totalPrice;
}
public boolean getIfStudent(){
return ifStudent;
}
public boolean getDeliverReq(){
return deliverReq;
}
public int getDeliveryPin(){
return deliverPin;
}
public double getDistance(){
return distance;
}
//setters
public void setOrder(Books[] newOrder){
order=newOrder;
}
public void setOrderObj(Books newOrderObj,int x){
order[x]=newOrderObj;
}
public void setFinalOrder(Order newFinalOrder){
finalOrder=newFinalOrder;
}
public void setPaymentMethod(int newPaymentMothed){
paymentMethod=newPaymentMothed;
}
public void setTotalPrice(double newTotal){
totalPrice=newTotal;
}
public void setIfStudent(boolean newIfStu){
ifStudent=newIfStu;
}
public void setDeliverReq(boolean newDeliverReq){
deliverReq=newDeliverReq;
}
public void setDeliveryPin(int newDeliveryPin){
deliverPin=newDeliveryPin;
}
public void setDistance(double distance){
this.distance=distance;
}
//methods
public void AddBook(int ch,Account cus, Books book){
if(cus instanceof Customer){
while(ch==1){
System.out.print("Enter the book ID for the book you want to add:");
int bookid=input.nextInt();
Books[] newOrder=new Books[cus.getCart().order.length+1];
if(book.getBookID()==bookid&&book.isAvailable()==true){
for(int i=0; i<order.length;i++){
newOrder[i]=cus.getCart().order[i];
}
newOrder[order.length]=book;
cus.getCart().setOrder(newOrder);
book.setQuantity(book.getQuantity()-1);
if(book instanceof Journals)
Journals.numOfJournals--;
if(book instanceof Studybooks)
Studybooks.numOfStudybooks--;
if(book instanceof Magazines)
Magazines.numOfMagazines--;
if(book.getQuantity()==0)
book.setAvailable(false);
System.out.println("Book Added");
System.out.println("You need to place order after this if your are done .. :)");
}
else
System.out.println("sorry book is out of stock");
System.out.println("if you want to add the same book type press 1 if you want out press any number");
ch=input.nextInt();
}
}
else
System.out.println("This feature is only for customers ");
}
public void PlaceOrder(Account cus,Books [] booksOrder, Distributor d1){
if(cus instanceof Customer){
System.out.println("Enter 1 for cash 2 for credit");
paymentMethod=input.nextInt();
System.out.println("--------------------------------------------------------------");
System.out.println("Are you a Student? if yes press 1 if no press 0");
int answer=input.nextInt();
if(answer==1){
ifStudent=true;
System.out.println("Congrats you have a discount");
}
System.out.println("--------------------------------------------------------------");
System.out.println("Do you want your order delivred? choose 1 for yes and 0 for no");
int answr=input.nextInt();
if(answr==1){
deliverReq=true;
}
else
deliverReq=false;
if(deliverReq==true){
deliverPin=(int)(Math.random()*50);
distance=(int)(Math.random()*(60-10)+10);
}
double sum=0.0;
for(int i=0; i<booksOrder.length; i++){
sum=sum+(booksOrder[i].getPrice());
totalPrice=sum;
}
if(cus.getCart().getIfStudent()==true){
totalPrice=(totalPrice*30)/100;
}
if(cus.getCart().deliverReq==true){
totalPrice=totalPrice+(d1.deliveryfee);
}
for(int i=0; i<booksOrder.length; i++){
finalOrder.getBookOrder().add(booksOrder[i]);
Order.numOfOrders++;}
cus.setCart(paymentMethod, ifStudent, deliverReq, deliverPin, totalPrice);
}
else
System.out.println("This feature is only for customers ");
}
public void cancelOrder(Account cus){
if(cus instanceof Customer){
System.out.println("Do you want to cancel your order ? ");
System.out.println("if yes type 1 if no type 0 ");
int answer=input.nextInt();
if(answer==1){
cus.getCart().order=null;
System.out.println("Order is cancelled");
Order.numOfOrders--;
}
else
System.out.println("Order is NOT cancelled");
}
else
System.out.println("This feature is only for customers ");
}
public void showBill(Account cus){
if(cus instanceof Customer){
do{
System.out.println("Order Details:");
if(cus.getCart().getOrder()==null){
System.out.println("Your order is cancalled!");
break;
}
if(cus.getCart().getOrder().length==0){
System.out.println("Your cart is empty!");
break;
}
if(cus.getCart().getOrder().length!=0)
System.out.println("Date Of Order:"+date.toString());
for(int i=0; i<cus.getCart().getOrder().length; i++){
System.out.println("Book ID["+(i+1)+"]: "+cus.getCart().getOrderObj(i).getBookID());
System.out.println("*****************************");
}
System.out.println("Quantity Bought:"+cus.getCart().getOrder().length);
System.out.println("*****************************");
cus.displayCart(cus);
System.out.println("*****************************");
break;
} while(false);
}
else
System.out.println("This feature is only for customers ");
}
}