-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataEvaluator.java
More file actions
313 lines (270 loc) · 11.1 KB
/
DataEvaluator.java
File metadata and controls
313 lines (270 loc) · 11.1 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package Git.MiniProject;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Scanner;
public class DataEvaluator {
public final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);
public String connectivityType(String connectivityType){
String result = "";
boolean repeatLoop;
do{
connectivityType = connectivityType.toUpperCase();
repeatLoop = false;
switch (connectivityType){
case "SS":
result = "SS";
break;
case "SF":
result = "SF";
break;
case "FS":
result = "FS";
break;
case "FF":
result = "FF";
break;
default:
System.out.println();
System.out.print("Correct choice is not made. Enter one of the following (SS, SF, FS, FF) ");
connectivityType = new KeyboardInput().Line();
repeatLoop = true;
break;
}
}while (repeatLoop);
return result;
}
public String yesOrNo(String choice){
choice = choice.toUpperCase();
String YES = "Y";
String NO = "N";
System.out.println();
while (!choice.equals(YES) && !choice.equals(NO)){
System.out.print("Correct choice is not made, Enter Y or N (for yes or no ");
choice = new KeyboardInput().Line();
choice = choice.toUpperCase();
}
return choice;
}
public String nameLength(String name){
int limitOfName = 30;
while (name.length() > limitOfName){
System.out.println("activity name shall be limited to 30 characters including spaces ");
System.out.println("Enter a shorter version of name for the activity ");
name = new KeyboardInput().Line();
}
return name;
}
public LocalDate extractConnectivityDate (String startOrFinish, ArrayList<Connectivity> connectivity){
int numberOfConnectivity = connectivity.size();
ArrayList<LocalDate> starts = new ArrayList<>();
ArrayList<LocalDate> finishes = new ArrayList<>();
LocalDate startDate;
LocalDate finishDate;
LocalDate result = null;
for (int i = 0; i < numberOfConnectivity; i++){
Connectivity con = connectivity.get(i);
String type = con.getStartOrFinish();
if(type.equals("FS") && con.getLinkedTo().getPlannedFinish() != null){
long days = con.getConnectivityDuration();
LocalDate otherTaskFinish = con.getLinkedTo().getPlannedFinish();
if( days > 0){
startDate = otherTaskFinish.plusDays(days);
}else{
days = (-1) * days;
startDate = otherTaskFinish.minusDays(days);
}
starts.add(startDate);
}else if(type.equals("SS") && con.getLinkedTo().getPlannedStart() != null){
long days = con.getConnectivityDuration();
LocalDate otherTaskStart = con.getLinkedTo().getPlannedStart();
if( days > 0){
startDate = otherTaskStart.plusDays(days);
}else{
days = (-1) * days;
startDate = otherTaskStart.minusDays(days);
}
starts.add(startDate);
}else if(type.equals("SF") && con.getLinkedTo().getPlannedStart() != null){
long days = con.getConnectivityDuration();
LocalDate otherTaskStart = con.getLinkedTo().getPlannedStart();
if( days > 0){
finishDate = otherTaskStart.plusDays(days);
}else{
days = (-1) * days;
finishDate = otherTaskStart.minusDays(days);
}
finishes.add(finishDate);
}else if(type.equals("FF") && con.getLinkedTo().getPlannedFinish() != null){
long days = con.getConnectivityDuration();
LocalDate otherTaskFinish = con.getLinkedTo().getPlannedFinish();
if( days > 0){
finishDate = otherTaskFinish.plusDays(days);
}else{
days = (-1) * days;
finishDate = otherTaskFinish.minusDays(days);
}
finishes.add(finishDate);
}
}
if(startOrFinish.equals("start") && starts.size() > 0){
int numberOfStarts = starts.size();
Collections.sort(starts);
result = starts.get((numberOfStarts - 1));
}else if(startOrFinish.equals("finish") && finishes.size() > 0){
Collections.sort(finishes);
result = finishes.get((0));
}
return result;
}
public void resourceAllocation(Project project){
ArrayList<Task> tasks = project.getTasks();
for(int i = 0; i < tasks.size(); i++){
Task currentTask = tasks.get(i);
}
}
public LocalDate readDate(){
boolean repeat;
int year = 0;
int month = 0;
int day = 0;
LocalDate today = LocalDate.now();
do{
repeat = false;
System.out.print("(YYYY/MM/DD) : ");
String rawDate = new KeyboardInput().Line();
String yearString = rawDate.substring(0,4);
String monthString = rawDate.substring(5,7);
String dayString = rawDate.substring(8);
String yearCopy = yearString;
String monthCopy = monthString;
String dayCopy = dayString;
yearCopy = yearCopy.replaceAll("[0-9]","");
monthCopy = monthCopy.replaceAll("[0-9]","");
dayCopy = dayCopy.replaceAll("[0-9]","");
if((yearCopy.length()+monthCopy.length()+dayCopy.length()) != 0){
repeat = true;
}else{
year = Integer.parseInt(yearString);
month = Integer.parseInt(monthString);
day = Integer.parseInt(dayString);
if(year > today.getYear()){
System.out.print("Year, ");
repeat = true;
}else if (month > 12){
System.out.print("Month, ");
repeat = true;
}else if(day > monthDays(year,month)){
System.out.print("Day ");
}
}
if(repeat){
System.out.print("Input needs correction. Enter Again");
}
}while (repeat);
return LocalDate.of(year,month,day);
}
//evaluates a name
public String name(String name){
final int FIRST = 0;
final int SECOND = 1;
final int ONE = 1;
name = name.toLowerCase();
////changing the first letter to upper case
name = name.substring(FIRST,SECOND).toUpperCase() + name.substring(SECOND);
if (name.contains(" ")){ //if the name have a space
int space = name.indexOf(" "); //index of the space
String name1 = name.substring(FIRST,space); //first name (capitalized earlier)
String name2 = name.substring(space + ONE); //second name
//second name first letter capitalized
name2 = name2.substring(FIRST,SECOND).toUpperCase() + name2.substring(SECOND);
name = name1 + " " + name2; //concatenation
}
return name;
}
public int year(int year){
final int NOT_ACCEPTABLE_YEAR = 0;
final int MIN_AGE = 0;
final int MAX_AGE = 100;
while((CURRENT_YEAR - year) < MIN_AGE ){
System.out.println("Year cannot be less that current year");
System.out.println("Enter year again ");
year = new KeyboardInput().Int();
}
return year;
}
//evaluates the month in SSN input
public int month(int month){
final int NOT_ACCEPTABLE_MONTH = 0;
final int MIN = 0;
final int MAX = 12;
if(month < MIN || month > MAX) {
return NOT_ACCEPTABLE_MONTH;
}
return month;
}
public int date (int date){
final int NOT_ACCEPTABLE_DATE = 0;
final int MIN = 0;
final int MAX = 31;
if(date < MIN || date > MAX) {
return NOT_ACCEPTABLE_DATE;
}
return date;
}
//evaluates the number of days in a month
public int monthDays(int year, int month){
final int NOT_ACCEPTABLE_YEAR_MONTH = 0;
final int MIN = 0;
final int MAX = 12;
if(year < MIN || month > MAX || month < MIN) {
return NOT_ACCEPTABLE_YEAR_MONTH;
}//this may not happen as our program make sure that the data is right
//java method to find the information of particular month of a particular year
YearMonth yearMonth = YearMonth.of(year,month);
//java method to find the number of days in a month of particular year
return yearMonth.lengthOfMonth();
}
//Double inputs collection
public double positiveDouble(String typedKey){
double evaluatedKey = 0.0;
final int YES = 0;
final int ZERO = 0;
int repeat = 0;
Scanner newKeyTyped = new Scanner(System.in);
while (repeat == YES ){
int initialLength = typedKey.length();
if(typedKey.contains("-") && typedKey.indexOf("-") == ZERO){ //if the string is negative
System.out.println("A positive value is needed");
}
// every character except numbers will be replaced by empty string
String shortedText = typedKey.replaceAll("[^0-9.]", "");
int finalLength = shortedText.length();
// if the input is only of numbers and if input is not empty string
if ((initialLength == finalLength) && !typedKey.equals("")){
evaluatedKey = Double.parseDouble(typedKey); // the input string is converted to Double
repeat++;
} else { //otherwise the input is not a valid number format and another try will be made
System.out.print("Please enter the required type of input. ");
typedKey= newKeyTyped.nextLine();
repeat = YES;
}
}
return evaluatedKey;
}
public double roundDouble(double number, int digitAfterDecimal){
double multiplier = 1.0;
double STANDARD = 10.0;
while (digitAfterDecimal < 0){
System.out.println("Digit after decimal should not be negative.");
System.out.println("Enter a positive number for the digits after the decimal");
digitAfterDecimal = new KeyboardInput().positiveInt();
}
for(int i = 0; i < digitAfterDecimal; i++){
multiplier = STANDARD * multiplier;
}
return Math.round(number * multiplier) / multiplier;
}
}