-
Notifications
You must be signed in to change notification settings - Fork 482
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
[Qin Nanxin] iP #572
base: master
Are you sure you want to change the base?
[Qin Nanxin] iP #572
Changes from 16 commits
28ad2b8
ed6d4d2
abfac81
517a3a2
5130bfd
5823330
59f198a
5f799dd
227c818
c8a51aa
b60464f
fb28447
cb37643
06d749e
ccefdd8
c5e5035
f6fa252
268ecd1
ec71f5a
2832520
8e0a3da
bc254bf
bc20f51
5591645
90fb38b
b0c2294
e1e5352
1b46958
60851c5
9ee8913
13f7891
0915f76
f1b52a4
48e1b39
3e9730d
e3f32d4
4ef7983
cbba5e0
14daed2
454b9ec
83021ff
202d315
3a6c213
f270bbc
87585ce
0264fab
64cd33a
677a0a3
e9c434c
c9b3825
e62e810
9c23bc9
f1ca54a
59dedbd
7c5fc1f
8cc478f
69a2e5d
96b6642
17e9d8b
066511a
34a161e
22fc82a
91503fa
77e2a1d
47711eb
ca6addc
618da5b
f7d2b25
6182e16
ad511a3
a87b8a8
c77c2bb
27af30c
55a69f3
699769d
722c222
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,22 @@ | ||
public class Deadline extends Task { | ||
private String deadline; | ||
|
||
public Deadline(String Task, String deadline) throws DukeException{ | ||
super(Task); | ||
this.deadline = deadline; | ||
|
||
// if (task.isBlank() || task.isEmpty()) { | ||
// throw new DukeException("The description of a Deadline task cannot be empty."); | ||
// } | ||
|
||
// if (deadline.isBlank() || deadline.isEmpty()) { | ||
// throw new DukeException("The deadline of a Deadline task cannot be empty."); | ||
// } | ||
} | ||
|
||
@Override | ||
public String getStatus(){ | ||
String time = "(by: " + deadline + ")"; | ||
return "[Deadline]" + super.getStatus() + " " + time; | ||
} | ||
} |
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 indentation for the case blocks inside the switch statement within the try block does not follow the coding standard |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,94 @@ | ||
import java.util.*; | ||
|
||
public class Duke { | ||
public static String partition = "------------------------------------------------------------"; | ||
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 changing 'partition' to a final variable as it does not change, as well as fully capitalising the variable name to be 'PARTITION' |
||
public static ArrayList<Task> taskList = new ArrayList<Task>(); | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
Scanner sc = new Scanner(System.in); | ||
|
||
System.out.println(partition); | ||
System.out.println("Hello! I'm Edna-Duke."); | ||
System.out.println("What can I do for you?"); | ||
System.out.println(partition); | ||
|
||
String input = sc.next(); | ||
while(!input.equals("bye")) { | ||
try { | ||
switch(input){ | ||
case "list": | ||
print(); | ||
break; | ||
case "mark": | ||
int markItem = sc.nextInt(); | ||
taskList.get(markItem - 1).markDone(); | ||
break; | ||
case "unmark": | ||
int unmarkItem = sc.nextInt(); | ||
taskList.get(unmarkItem - 1).markUndone(); | ||
break; | ||
case "delete": | ||
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 making inputs case-insensitive! This way, if I requested to add a todo writing: tOdO it would still add the task into the list. |
||
int deleteItem = sc.nextInt(); | ||
delete(deleteItem); | ||
break; | ||
case "todo": | ||
add(new ToDo(sc.nextLine())); | ||
break; | ||
case "event": | ||
String eventCommand = sc.nextLine(); | ||
String[] event = new String[3]; | ||
event[0] = eventCommand.substring(1, eventCommand.indexOf(" /")); | ||
event[1] = eventCommand.substring(eventCommand.indexOf("/from") + 6, | ||
eventCommand.indexOf(" /to")); | ||
event[2] = eventCommand.substring(eventCommand.indexOf("/to") + 4); | ||
add(new Event(event[0], event[1], event[2])); | ||
break; | ||
case "deadline": | ||
String ddlCommand = sc.nextLine(); | ||
String[] ddl = ddlCommand.split(" /by "); | ||
add(new Deadline(ddl[0].substring(1), ddl[1])); | ||
break; | ||
default: | ||
add(new Task(input)); | ||
} | ||
} | ||
|
||
catch (DukeException e) { | ||
System.out.println(e.getMessage()); | ||
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. I think your method is too long here. Maybe try to create some other methods?😎 |
||
} | ||
|
||
finally { | ||
System.out.println(partition); | ||
input = sc.next(); | ||
} | ||
} | ||
|
||
exit(); | ||
} | ||
|
||
public static void add(Task input) { | ||
taskList.add(input); | ||
System.out.println("Got it! This task has been added: "); | ||
System.out.println(input.getStatus()); | ||
System.out.println("Current # of task: " + taskList.size()); | ||
} | ||
|
||
public static void delete(int num) { | ||
System.out.println("I've removed this task:"); | ||
taskList.get(num-1).getStatus(); | ||
taskList.remove(num - 1); | ||
System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
} | ||
|
||
public static void print() { | ||
int index = 1; | ||
for (Task task: taskList) { | ||
System.out.println(index + ". " + task.getStatus()); | ||
index ++; | ||
} | ||
} | ||
|
||
public static void exit() { | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
System.out.println(partition); | ||
} | ||
} | ||
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 & Formatting: The code seems to be properly indented, which makes it easier to read. Names like input, eventCommand, and ddlCommand are meaningful, but some variables like ddl could have a more descriptive name. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public class DukeException extends Exception { | ||
public DukeException(String message) { | ||
super(message); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return ":( Oh no! " + super.getMessage(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public class Event extends Task { | ||
private String from; | ||
private String to; | ||
|
||
public Event(String task, String from, String to) throws DukeException { | ||
super(task); | ||
this.from = from; | ||
this.to = to; | ||
|
||
// if (task.isBlank() || task.isEmpty()) { | ||
// throw new DukeException("The description of a Event task cannot be empty."); | ||
// } | ||
|
||
// if (from.isBlank() || from.isEmpty() || to.isBlank() || to.isEmpty()) { | ||
// throw new DukeException("The time of an Event task cannot be empty."); | ||
// } | ||
} | ||
|
||
@Override | ||
public String getStatus(){ | ||
String time = "(from: " + from + " to: " + to + ")"; | ||
return "[Event]" + super.getStatus() + " " + time; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
public class Task { | ||
String task; | ||
boolean isDone; | ||
|
||
public Task(String task) throws DukeException { | ||
//when the command didn't go through any of the given cases | ||
if (task == null){ | ||
throw new DukeException("I'm sorry, but I don't know what that means."); | ||
} | ||
this.task = task; | ||
this.isDone = false; | ||
} | ||
|
||
public String getTask() { | ||
return this.task; | ||
} | ||
|
||
public String getStatus() { | ||
String status = "[" + (isDone ? "✓" : "✗") + "]"; | ||
return status + " " + this.getTask(); | ||
} | ||
|
||
public void markDone() { | ||
this.isDone = true; | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(this.getStatus()); | ||
System.out.println("Here's a lollipop. 🍭"); | ||
} | ||
|
||
public void markUndone() { | ||
this.isDone = false; | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
System.out.println(this.getStatus()); | ||
System.out.println("Undone complete."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class ToDo extends Task { | ||
public ToDo(String task)throws DukeException { | ||
super(task); | ||
if (task.isBlank() || task.isEmpty()) { | ||
throw new DukeException("The description of a To-Do task cannot be empty."); | ||
} | ||
} | ||
|
||
@Override | ||
public String getStatus() { | ||
return "[To-Do]" + super.getStatus(); | ||
} | ||
} | ||
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. This program has only finished Week1-2 tasks, more OOP should be added |
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.
Overall good job! Good use of abstraction using the Task class! However, it might be a better idea to have even more abstraction through the addition of a UI class that handles all the printing and a TaskList class that handles the list of Tasks.