-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectApplication.java
309 lines (256 loc) · 11 KB
/
ProjectApplication.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
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
//Nick Arboscello
import java.util.ArrayList;
import java.util.Scanner;
/**
* The ProjectApplication class represents the main application for managing projects, users, and related functionality.
*/
public class ProjectApplication {
private ProjectList projectList;
private UserList userList;
private User user;
private Scanner scanner = new Scanner(System.in);
/**
* Constructs a new ProjectApplication object.
*/
public ProjectApplication() {
projectList = new ProjectList(); // Initialize projectList
userList = new UserList(); // Initialize userList
user = null; // Initialize user
}
/**
* Creates a new user account.
*
* @param firstName The first name of the user.
* @param lastName The last name of the user.
* @return The newly created User object.
*/
public void signUp() {
UserList userList = UserList.getInstance();
String userName = getField("Enter your username");
String password = getField("Enter your password");
String firstName = getField("Enter your first name");
String lastName = getField("Enter your last name");
String email = getField("Enter your email");
int privacyLevel = Integer.parseInt(getField("Enter your privacy level"));
UserList.addUser(userName, password, firstName, lastName, email, privacyLevel);
DataWriter.saveUsers();
}
/**
* Attempts to log in a user with the given username and password.
*
* @param username The username of the user.
* @param password The password of the user.
* @return The User object if login is successful, repeat the login process otherwise, exit if the user chooses to.
*/
public void logIn() {
UserList userList = UserList.getInstance();
String userName = getField("Enter your username");
String password = getField("Enter your password");
if (UserList.isValidLogin(userName, password)) {
System.out.println("Login successful!");
user = UserList.getUser(userName);
} else {
System.out.println("Invalid login. Please try again.");
logIn();
}
}
/**
* Gets a field from the user.
* @param prompt
* @return
*/
private String getField(String prompt) {
System.out.println(prompt + ": ");
return scanner.nextLine();
}
/**
* Retrieves a list of all projects.
*
* @return A list of all projects.
*/
public void getAllProjects() {
ProjectList projectList = ProjectList.getInstance();
ArrayList<Project> projects = projectList.getProjectList();
for (Project project : projects) {
System.out.println(project.getProjectName());
}
}
/**
* Creates a new project.
*
* @return True if the project is created successfully, false otherwise.
*/
public Project createProject() {
ProjectList projectList = ProjectList.getInstance();
String projectName = getField("Enter the project name");
String projectDesc = getField("Enter the project description");
String projectAuthor = getField("Enter the project author");
ProjectList.addProject(projectName, projectDesc, projectAuthor);
return new Project(projectName, projectDesc, projectAuthor);
}
/**
* Finds and returns a list of matching projects based on some criteria.
*
* @return A list of matching projects.
*/
public ArrayList<Project> findProject() {
ProjectList projectList = ProjectList.getInstance();
ArrayList<Project> projects = projectList.getProjectList();
String projectName = getField("Enter the project name");
ArrayList<Project> matchingProjects = new ArrayList<Project>();
for (Project project : projects) {
if (project.getProjectName().equals(projectName)) {
matchingProjects.add(project);
}
}
return matchingProjects;
}
/**
* Opens a project with the given projectId.
*
* @param projectName The name of the project to be opened.
* @return True if the project is opened successfully, false otherwise.
*/
public void openProject() {
ProjectList projectList = ProjectList.getInstance();
ArrayList<Project> projects = projectList.getProjectList();
Scanner input = new Scanner(System.in);
String projectName = getField("Enter the project name");
for (Project project : projects) {
if (project.getProjectName().equals(projectName)) {
System.out.println("Project Name: "+project.getProjectName());
System.out.println("Description: "+project.getProjectDesc());
System.out.println("Project Author: "+project.getProjectAuthor());
System.out.println("_____________________________________________");
project.printBoard();
if (project != null) {
boolean projectMenuRunning = true;
while (projectMenuRunning) {
System.out.println("What would you like to do in " + project.getProjectName() + "?");
System.out.println("1. Show board");
System.out.println("2. Move tasks");
System.out.println("3. Add comment");
System.out.println("4. Show comments");
System.out.println("5. Go back");
System.out.println("_________________________");
int projectChoice = input.nextInt();
input.nextLine();
switch (projectChoice) {
case 1:
System.out.println("show board\n___________________");
project.printBoard();
break;
case 2:
System.out.println("move task\n___________________");
break;
case 3:
System.out.println("add comm\n___________________");
break;
case 4:
System.out.println("show comm\n___________________");
break;
case 5:
projectMenuRunning = false;
break;
default:
System.out.println("Invalid choice. Please try again.");
break;
}
}
} else {
System.out.println("Project not found.");
}
}
}
}
/**
* Creates a new task for a project.
*
* @return True if the task is created successfully, false otherwise.
*/
public Task createTask(){
Scanner scanner = new Scanner(System.in);
TaskList task = TaskList.getInstance();
ArrayList<Task> taskList = task.geTasksList();
ArrayList<Comment> comment = new ArrayList<Comment>();
boolean checker = true;
ProjectList projectList = ProjectList.getInstance();
ArrayList<Project> projects = projectList.getProjectList();
Column column;
System.out.println("Enter the project name in which you would like to add a task");
String projectName = scanner.nextLine();
for (Project project : projects) {
if (project.getProjectName().equals(projectName)) {
System.out.println("Project Name: "+project.getProjectName());
System.out.println("Description: "+project.getProjectDesc());
System.out.println("Project Author: "+project.getProjectAuthor());
System.out.println("_____________________________________________");
project.printBoard();
}
}
String taskName = getField("Enter the task name");
String taskDesc = getField("Enter the task description");
String taskAuthor = getField("Enter the task author");
String Catego = getField("Enter the task Category");
Catego = Catego.toUpperCase();
column = new Column(Catego);
Category cat = Category.BUG;
System.out.println("Enter the priority.(enter a number)");
int taskPrio = scanner.nextInt();
System.out.println("Is it in progress True or false");
boolean inProgres = scanner.nextBoolean();
System.out.println("Enter the Privacy.(enter a number)");
int taskPriv = scanner.nextInt();
String color = getField("What color would you like it to be. Red, Blue, or Green ");
if(color.equalsIgnoreCase("red")) {
color = "ff0000";
} else if (color.equalsIgnoreCase("Blue")) {
color = "0000FF";
} else if (color.equalsIgnoreCase("Green")) {
color = "008000";
} else {
color = "#000000";
}
while(checker) {
String addCom = getField("would you like to add a Comment. Y/N");
if(addCom.equalsIgnoreCase("Y")) {
createComment(comment);
checker = false;
} else if(addCom.equalsIgnoreCase("N")) {
comment.add(new Comment("N/A", "N/A", "N/A"));
checker = false;
} else {
checker = true;
}
}
Task currentTask = new Task(taskName, taskDesc, taskPrio, cat, comment, inProgres, taskPriv, color);
column.addTask(currentTask);
TaskList.addTask(taskName, taskDesc, taskPrio, cat, comment, inProgres, taskPriv, color);
return new Task(taskName, taskDesc, taskPrio, cat, comment, inProgres, taskPriv, color);
}
/**
* Creates a new comment for a task.
*
* @param commentAuth The user authoring the comment.
* @param commentText The text of the comment.
* @return True if the comment is created successfully, false otherwise.
*/
public void createComment(ArrayList<Comment> comment) {
ProjectList projectList = ProjectList.getInstance();
ArrayList<Project> projects = projectList.getProjectList();
String commentAuth = getField("Enter the comment author");
String commentText = getField("Enter the comment text");
String commentDate = getField("Enter the comment date");
comment.add(new Comment(commentAuth, commentText, commentDate));
}
public void printTask() {
}
/**
* Edits a task with the given taskId.
*
* @param taskId The ID of the task to be edited.
* @param task The updated task information.
*/
public void editTask(String taskName, ArrayList<String> task) {
}
}