-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZhuliUser.java
206 lines (180 loc) · 7.48 KB
/
ZhuliUser.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
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
import java.util.*;
import java.time.*;
public class ZhuliUser {
// instance variables
public String name;
public String username;
private String password;
public Boolean isBusy;
public int id;
public static int nextID = 1001;
public Heap tasks;
private Boolean passwordCreated;
// instance variables for scheduling
public DayOfWeek[] daysOfWeekArray = {DayOfWeek.SUNDAY, DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY, DayOfWeek.SATURDAY};
public Hashtable<DayOfWeek, Double> day_hoursHash;
public String workerType;
public Boolean workerTypeSet;
//constructor
public ZhuliUser () {
// create id
this.id = nextID;
nextID++;
this.workerTypeSet = false;
this.workerType = "Adriana";
// create username
Scanner keyboard = new Scanner(System.in);
System.out.print("choose a username ");
this.username = keyboard.nextLine();
System.out.print("What should I call you? ");
this.name = keyboard.nextLine();
// create password
this.passwordCreated = false;
while (!passwordCreated) {
System.out.print("Create your password ");
String tempPassword = keyboard.nextLine();
System.out.print("re-enter your password ");
String reEnteredPassword = keyboard.nextLine();
if (reEnteredPassword.equals(tempPassword)) {
System.out.println("Passwords match");
this.password = tempPassword;
this.passwordCreated = true;
}
else {
System.out.println("Sorry, the passwords didn't match. Please try again.");
}
}
// user is not busy
this.isBusy = false;
// create empty heap of tasks
tasks = new Heap();
day_hoursHash = new Hashtable<DayOfWeek, Double>(7); // capacity of 7
for (DayOfWeek dayOfWeek : daysOfWeekArray) {
day_hoursHash.put(dayOfWeek, 6.);
}
keyboard.close();
}
public String toString() {
return String.format("Name: %d user name: %s type of worker: %s", this.name, this.username, this.workerType);
}
public ArrayList<Task> getTasks() {
return this.tasks.getOrderedArray();
}
private Boolean correctPassword(String passwordAttempt) {
if (passwordAttempt.equals(this.password)) {
return true;
}
return false;
}
public void addTask(Task newTask) {
Scanner keyboard = new Scanner(System.in);
System.out.print("please enter your password ");
String passwordAttempt = keyboard.nextLine();
if (!correctPassword(passwordAttempt)) {
System.out.println("AAAAAAAAAAHHHHH INTRUDER INTRUDER INTRUDER!!!! D:");
return;
}
this.tasks.add(newTask);
System.out.printf("%s was added to your tasks.\n", newTask);
}
public Double getHoursLeftInWeek(LocalDate today) {
DayOfWeek todaysDayOfWeek = today.getDayOfWeek();
Double totalHours = 0.;
Boolean active = false; // when true we begin to count the rest of the week
for (int i = 0; i < this.daysOfWeekArray.length; i++) {
Object day = this.daysOfWeekArray[i];
if (!active) {
if (day == todaysDayOfWeek) {
active = true;
}
}
if (active) {
totalHours += this.day_hoursHash.get(day);
}
}
return totalHours;
}
public Double getMaxWorkHours(DayOfWeek day) {
return this.day_hoursHash.get(day);
}
public void setPreferences() {
Scanner keyboard = new Scanner(System.in);
for (int i = 0; i < this.daysOfWeekArray.length; i++) {
Object day = this.daysOfWeekArray[i];
System.out.printf("Your preference is to work a maximum of %f hours on %ss. keep or change?\n", day_hoursHash.get(day), day);
String ans = keyboard.nextLine();
if (ans.equals("change")) {
System.out.printf("How many hours do you want to work on %ss (max)?\n", day);
String hrs = keyboard.nextLine();
Double workHrs = Integer.parseInt(hrs) / 1.;
DayOfWeek dayOfWk = (DayOfWeek) day;
this.day_hoursHash.replace(dayOfWk, this.day_hoursHash.get(day), workHrs); // change hrs worked that day
System.out.printf("Ok. You will work %f hours max!\n",day_hoursHash.get(day));
}
else if (ans.equals("keep")) {
System.out.printf("Ok. Your %ss will stay the same.\n", day);
}
}
System.out.println("What kind of worker are you? (Maybe a better question is what worker do you want to be?) Are you a...\n");
System.out.println("Susy - Susy likes to evenly space work throughout their week\nso that they don't feel overwhelmed\n");
System.out.println("Adriana - Adriana likes to plow through their work on certain days\nof the week so that they are free the rest of the week\n");
System.out.print("Susy or Adriana? ");
Boolean workerTypeSet = false;
while (!this.workerTypeSet) {
String worker = keyboard.nextLine();
if (worker.equals("Susy") || worker.equals("Adriana")) {
this.workerTypeSet = true;
if (worker.equals("Susy")) {
this.workerType = "Susy";
System.out.println("Ok I have you as a Susy!");
}
else {
this.workerType = "Adriana";
System.out.println("Ok I have you as an Adriana!");
}
}
else {
System.out.println("Sorry, you have to type 'Susy' or 'Adriana'");
}
}
keyboard.close();
System.out.println("Your preferences are set.");
}
public String getWorkerType() {
return this.workerType;
}
/*
//test
public static void main(String[] args) {
// todays date
LocalDate today = LocalDate.now();
//homeworks
Task hw1 = new Task("physics worksheet", 2, 2., 2020, 5, 8);
Task hw2 = new Task("finish ZhuLi", 3, 3., 2020, 5, 7);
Task hw3 = new Task("finish physics test", 3, 3., 2020, 5, 8);
Task hw4 = new Task("math oral exam", 4, 10., 2020, 5, 15);
ZhuliUser Mario = new ZhuliUser();
Mario.addTask(hw1);
Mario.addTask(hw2);
Mario.addTask(hw3);
Mario.addTask(hw4);
ArrayList<Task> tasksArray = Mario.getTasks();
System.out.println("hw1 task array returned");
String tasksString = tasksArray.toString();
System.out.printf("tasks are: %s\n", tasksString);
Double hrsLeft = Mario.getHoursLeftInWeek(today);
System.out.printf("hours left in week: %f\n", hrsLeft);
Mario.addTask(hw2);
Mario.getTasks();
Mario.getHoursLeftInWeek(today);
Mario.addTask(hw3);
Mario.getTasks();
Mario.getHoursLeftInWeek(today);
Mario.addTask(hw4);
Mario.getTasks();
Mario.getHoursLeftInWeek(today);
Mario.setPreferences();
Mario.getWorkerType();
}
*/
}