-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
61 lines (53 loc) · 1.56 KB
/
test.java
File metadata and controls
61 lines (53 loc) · 1.56 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
package org.midea.mall;
import java.util.Date;
import java.util.Calendar;
public class OrderSystem {
public static final String DEFAULT_ORDER_PREFIX = "ORD-";
private String orderId;
public OrderSystem() {
this.orderId = generateOrderId();
......
totalOrderCount++;
}
public double calculateTotal(double freight) {
return this.amount + freight;
}
public static String generateOrderId() {
Calendar cal = Calendar.getInstance();
.......
return DEFAULT_ORDER_PREFIX + year +
String.format("%02d", month) +
String.format("%02d", day) +
"-" + (totalOrderCount + 1);
}
// 静态函数:获取当前系统时间
public static Date getCurrentDate() {
return new Date();
}
// 实例函数:拼接订单信息
public String getOrderInfo() {
return "订单ID:" + orderId +
"\n订单金额:¥" + amount +
"\n创建时间:" + createTime +
"\n订单状态:" + status.getDescription();
}
// Getter/Setter(访问实例变量的函数)
public String getOrderId() {
return orderId;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public Date getCreateTime() {
return createTime;
}
public OrderStatus getStatus() {
return status;
}
public void setStatus(OrderStatus status) {
this.status = status;
}
}