-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.java
74 lines (61 loc) · 2.12 KB
/
User.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
import java.util.*;
public class User {
/** list of integers for each user's preferences */
private List<Double> preferences;
/** String containing the username of the user
* requires: username cannot be empty
*/
private String username;
/** list of previous transaction data */
private List<Product> transactions;
/**
* User location
*/
private Point loc;
/** creates a user with username name and default preferences (weighted toward green) */
public User (String name) {
username = name;
loc = new Point();
preferences = new ArrayList<>();
preferences.add(0.3);
preferences.add(0.3);
preferences.add(0.2);
preferences.add(0.2);
transactions = new ArrayList<Product>();
}
/** returns the username of the person */
public String username() {
return username;
}
public Point getLoc(){
return loc;
}
public void setLoc(Point a){
loc = a;
}
/** returns a list of preferences, where the first index corresponds to transportation
* score, second index corresponds to how it was made, third index corresponds to cost,
* fourth index corresponds to organic
*/
public List<Double> preferences() {
List<Double> userPreferences = new ArrayList<>();
userPreferences.add(preferences.get(0));
userPreferences.add(preferences.get(1));
userPreferences.add(preferences.get(2));
userPreferences.add(preferences.get(3));
return userPreferences;
}
/** adds a transaction of purchases to the list of transactions and updates preferences
* based on the new purchase
*/
public void addTransaction(Product purchase, double averageCost) {
transactions.add(purchase);
List<Double> scores = purchase.scores(averageCost);
for (int i = 0; i < 4; i++) {
double currentPreference = preferences.get(i);
double change = (scores.get(i) - currentPreference) * 0.1;
currentPreference += change;
preferences.set(i, currentPreference);
}
}
}