Repository navigation
Expand file tree
/
Copy pathOrder
More file actions
68 lines (54 loc) · 1.61 KB
/
Copy pathOrder
File metadata and controls
68 lines (54 loc) · 1.61 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package pkg230315082.oop.homework;
/**
*
* @author 7Z4M9EA
*/
public class Order {
private User user;
private Product product;
private CreditCard creditCard;
private int quantity;
public Order(User user, Product product, CreditCard creditCard, int quantity) {
this.creditCard = creditCard;
this.product = product;
this.user = user;
this.quantity = quantity;
}
public void processOrder() {
if (product.checkStock(quantity)) {
product.reduceStock(quantity);
user.getOrders().add(this);
System.out.println("Order processed:" + quantity + "x" + product.getProductName());
} else {
System.out.println("You cannot order this product,the stock is not enough:" + product.getProductName());
}
}
public User getUser() {
return user;
}
public Product getProduct(){
return product;
}
public CreditCard getCreditCard(){
return creditCard;
}
public int getQuantity(){
return quantity;
}
public void setUser(User user) {
this.user = user;
}
public void setProduct(Product product){
this.product = product;
}
public void setCreditCard(CreditCard creditCard){
this.creditCard = creditCard;
}
public void setQuantity(int quantity){
this.quantity = quantity;
}
}