-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGoods.java
More file actions
70 lines (62 loc) · 2.36 KB
/
Copy pathGoods.java
File metadata and controls
70 lines (62 loc) · 2.36 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
package test1;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Goods {
public int ID;
public String name;
public String belongingArea;
public String sendingArea;
public int type;
public int clientGrade;
public String date;
public double priority;
private final float typeWeight = 0.2f;
private final float clientGradeWeight = 0.3f;
private final float dateWeight = 0.4f;
private static long todayTimestamp = new Date().getTime();
private static long oneDayTimestamp = 24 * 60 * 60 * 1000;
public Goods(int ID, String name, String belongingArea, String sendingArea, int type, int clientGrade, String date) {
this.ID = ID;
this.name = name;
this.belongingArea = belongingArea;
this.sendingArea = sendingArea;
this.type = type;
this.clientGrade = clientGrade;
this.date = date;
this.priority = weight(type, clientGrade, date);
}
public double getPriority(){
return priority;
}
private double weight(int type, int clientGrade, String dateString) {
double date = Math.ceil((todayTimestamp - SimpleDateFormat(dateString)) / oneDayTimestamp);
return type * typeWeight + clientGrade * clientGradeWeight + date * dateWeight;
}
private long SimpleDateFormat(String strDate) {
//注意:SimpleDateFormat构造函数的样式与strDate的样式必须相符
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //加上时间
//必须捕获异常
try {
Date date = simpleDateFormat.parse(strDate);
return date.getTime();
} catch (ParseException px) {
px.printStackTrace();
}
return 0;
}
@Override
public String toString() {
return "Goods{" +
"ID=" + ID +
", name='" + name + '\'' +
", origin='" + belongingArea + '\'' +
", destination='" + sendingArea + '\'' +
", type=" + type +
", client_level=" + clientGrade +
", date='" + date + '\'' +
", priority=" + Utils.format(priority) +
'}';
}
}