-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Aaron Chan Zhi] iP #73
base: master
Are you sure you want to change the base?
Changes from 1 commit
e85afad
52a99bb
150fe48
331f166
fa24764
b8d7ebf
8226e88
468217a
57f5e5b
c84fc42
7878253
6f0ba3e
ef55e2a
0dc6154
220ffab
7b7655d
d2d116b
0d3c5f2
a896371
535e3d5
700f8dc
58d565c
6e29fb5
8b48fe4
45f6814
4952e2e
02a4770
bb1accf
15debf3
16e254f
afdc14c
a2517fd
8d80670
64900ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Deadline extends Task { | ||
private String dueDate; | ||
|
||
public Deadline(String description, String dueDate){ | ||
this.description = description; | ||
this.isDone = false; | ||
this.taskType = "D"; | ||
this.dueDate = dueDate; | ||
} | ||
|
||
public String getDueDate(){ | ||
return this.dueDate; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ public class Duke { | |
public static void main(String[] args) { | ||
boolean isExit = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative name can be used for the boolean isExit so that the purpose of the boolean is clearer |
||
Scanner scanner = new Scanner(System.in); | ||
TaskList task_list = new TaskList(); | ||
TaskList taskList = new TaskList(); | ||
|
||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
|
@@ -23,16 +23,17 @@ public static void main(String[] args) { | |
//Getting Input | ||
System.out.println("---------------------------------------------------"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. potentially add ---------... as a constant to increase readability of print statements. |
||
System.out.print("You: "); | ||
String raw_input = scanner.nextLine(); | ||
String[] input_list = raw_input.split(" "); | ||
String cmd = input_list[0]; | ||
String rawInput = scanner.nextLine(); | ||
String[] inputList = rawInput.split(" "); | ||
String cmd = inputList[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name of variable can be improve, for example rather than cmd, it can be command There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider writing variable names in full to make it more readable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could consider renaming the variable to "command" so that it is clearer to the reader |
||
String description; | ||
|
||
//Responding | ||
switch (cmd) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The switch statement should be aligned with the case statements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can do the printing in another method to make the code look cleaner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation not needed for switch and case statements |
||
case ("list"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid magic strings, so maybe for each of these cases, you can say for ex: LIST = "list" and reference the constant in the if statement |
||
System.out.println("---------------------------------------------------"); | ||
System.out.println("Tasks: "); | ||
task_list.printList(); | ||
taskList.printList(); | ||
break; | ||
case ("bye"): | ||
isExit = true; | ||
|
@@ -44,16 +45,71 @@ public static void main(String[] args) { | |
System.out.println("---------------------------------------------------"); | ||
System.out.println("Marked as done:"); | ||
|
||
String task_description = String.join(" ", Arrays.copyOfRange(input_list, 1, input_list.length)); | ||
task_list.searchTask(task_description).markAsDone(); | ||
description = String.join(" ", Arrays.copyOfRange(inputList, 1, inputList.length)); | ||
taskList.searchTask(description).markAsDone(); | ||
|
||
System.out.print("[X] "); | ||
System.out.println(task_description); | ||
System.out.println(description); | ||
break; | ||
default: //Add to list | ||
case ("unmark"): | ||
System.out.println("---------------------------------------------------"); | ||
System.out.println("Added: " + raw_input); | ||
task_list.addTask(raw_input); | ||
System.out.println("Marked as not completed:"); | ||
|
||
description = String.join(" ", Arrays.copyOfRange(inputList, 1, inputList.length)); | ||
taskList.searchTask(description).markAsNotDone(); | ||
|
||
System.out.print("[ ] "); | ||
System.out.println(description); | ||
break; | ||
case ("todo"): //Add to list | ||
System.out.println("---------------------------------------------------"); | ||
description = String.join(" ", Arrays.copyOfRange(inputList, 1, inputList.length)); | ||
System.out.println("Added:"); | ||
System.out.println(" [T][ ] " + description); | ||
taskList.addToDo(description); | ||
System.out.println("Now you have " + taskList.getSize() + " tasks in the list."); | ||
break; | ||
case ("deadline"): | ||
System.out.println("---------------------------------------------------"); | ||
int byPosition = 0; | ||
String dueDate; | ||
for (int i=0; i<inputList.length; i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could consider adding spaces before and after comparison operators to improve readability |
||
if (inputList[i].equals("by")) { | ||
byPosition = i; | ||
break; | ||
} | ||
} | ||
if (byPosition == 0){ | ||
System.out.println("Please state the deadline!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job on adding error handling! |
||
break; | ||
} | ||
description = String.join(" ", Arrays.copyOfRange(inputList, 1, byPosition)); | ||
dueDate = String.join(" ", Arrays.copyOfRange(inputList, byPosition+1, inputList.length)); | ||
System.out.println("Added:"); | ||
System.out.println(" [D][ ] " + description + " (by: " + dueDate + ")"); | ||
taskList.addDeadline(description, dueDate); | ||
System.out.println("Now you have " + taskList.getSize() + " tasks in the list."); | ||
break; | ||
case ("event"): | ||
System.out.println("---------------------------------------------------"); | ||
int atPosition = 0; | ||
String dateTime; | ||
for (int i=0; i<inputList.length; i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding spaces in between calculations |
||
if (inputList[i].equals("at")){ | ||
atPosition = i; | ||
break; | ||
} | ||
} | ||
if (atPosition == 0){ | ||
System.out.println("Please state the date and time!"); | ||
break; | ||
} | ||
description = String.join(" ", Arrays.copyOfRange(inputList, 1, atPosition-1)); | ||
dateTime = String.join(" ", Arrays.copyOfRange(inputList, atPosition+1, inputList.length)); | ||
System.out.println("Added:"); | ||
System.out.println(" [E][ ] " + description + " (at: " + dateTime + ")"); | ||
taskList.addEvent(description, dateTime); | ||
System.out.println("Now you have " + taskList.getSize() + " tasks in the list."); | ||
break; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Event extends Task { | ||
protected String dateTime; | ||
|
||
public Event(String description, String dateTime){ | ||
this.description = description; | ||
this.isDone = false; | ||
this.taskType = "E"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make taskType a static final variable and instantiate it not in the constructor |
||
this.dateTime = dateTime; | ||
} | ||
|
||
public String getDateTime(){ | ||
return this.dateTime; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
public class Task { | ||
public String description; | ||
protected String taskType; | ||
protected boolean isDone; | ||
|
||
public Task(String description){ | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); | ||
} | ||
|
||
public String getTaskType(){ | ||
return taskType; | ||
} | ||
|
||
public void setTaskType(String type){ | ||
taskType = type; | ||
} | ||
|
||
public void markAsDone() { | ||
if (isDone==false) this.isDone = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add spaces before and after the logical operator so that it looks better |
||
} | ||
|
||
public void markAsNotDone(){ | ||
if (isDone==true) this.isDone = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just do: |
||
} | ||
|
||
public String getDueDate(){ | ||
return " "; | ||
} | ||
public String getDateTime(){ | ||
return " "; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,58 @@ | ||
import java.util.ArrayList; | ||
|
||
public class TaskList{ | ||
|
||
public int size = 0; | ||
protected ArrayList<Task> list = new ArrayList<Task>(); | ||
|
||
public TaskList(){} | ||
|
||
public void addTask(String task_name){ | ||
Task task = new Task(task_name); | ||
list.add(task); | ||
public void addToDo(String description){ | ||
ToDo toDo = new ToDo(description); | ||
list.add(toDo); | ||
this.size++; | ||
} | ||
|
||
public void addDeadline(String description, String dueDate){ | ||
Deadline deadline = new Deadline(description, dueDate); | ||
list.add(deadline); | ||
this.size++; | ||
} | ||
|
||
public void addEvent(String description, String dateTime){ | ||
Event event = new Event(description, dateTime); | ||
list.add(event); | ||
this.size++; | ||
} | ||
|
||
public Task getTask(int index){ | ||
return list.get(index); | ||
return (Task)list.get(index); | ||
} | ||
|
||
public void printList(){ | ||
for (int i=0; i<size; i++){ | ||
Task tempTask = this.getTask(i); | ||
System.out.print((i+1) + ") "); | ||
System.out.print("[" + tempTask.getStatusIcon() + "] "); | ||
System.out.println(tempTask.description); | ||
String taskType = tempTask.getTaskType(); | ||
if (taskType == "T"){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the printing can be done in a method to prevent repetition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Magic String, maybe set "T" as a constant TASK = "T" so its easier for readers to know that T corresponds to task :) |
||
tempTask = (ToDo)tempTask; | ||
System.out.print((i+1) + ") "); | ||
System.out.print("[" + tempTask.getTaskType() + "]"); | ||
System.out.print("[" + tempTask.getStatusIcon() + "] "); | ||
System.out.println(tempTask.description); | ||
} else if (taskType == "D"){ | ||
tempTask = (Deadline) tempTask; | ||
System.out.print((i+1) + ") "); | ||
System.out.print("[" + tempTask.getTaskType() + "]"); | ||
System.out.print("[" + tempTask.getStatusIcon() + "] "); | ||
System.out.print(tempTask.description); | ||
System.out.println(" (by: " + tempTask.getDueDate() + ")"); | ||
} else if (taskType == "E"){ | ||
tempTask = (Event) tempTask; | ||
System.out.print((i+1) + ") "); | ||
System.out.print("[" + tempTask.getTaskType() + "]"); | ||
System.out.print("[" + tempTask.getStatusIcon() + "] "); | ||
System.out.print(tempTask.description); | ||
System.out.println(" (by: " + tempTask.getDateTime() + ")"); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -32,4 +63,8 @@ public Task searchTask(String task_description){ | |
} | ||
return null; | ||
} | ||
|
||
public int getSize(){ | ||
return size; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public class ToDo extends Task { | ||
|
||
public ToDo(String description){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding spaces in between method name and inputs |
||
this.description = description; | ||
this.isDone = false; | ||
this.taskType = "T"; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be spacing before braces (applies the whole file)