-
Notifications
You must be signed in to change notification settings - Fork 361
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
[bryanongjx] iP #379
base: master
Are you sure you want to change the base?
[bryanongjx] iP #379
Changes from 8 commits
556af3f
e2dc23c
9db8e00
20ce1ef
e948091
89bdac5
7b40056
81c9a07
7214d96
cf92c42
5a3100f
58a445a
4f6015e
1b62400
7f63b95
a3e7ddd
3b342e4
66cf005
7304d67
8149068
a751546
a4305f5
75434c3
d0ee74a
89cb4cb
9a048bb
6b62d7c
281887a
ec4f38b
125a1ba
54966ee
4c1d6c5
cb80e43
9773ae4
abc3980
61ba68b
8ce8ade
ec6df17
56e199b
d0d6670
c10b1b7
9625384
3a259b7
0d4c3b6
5df8906
c490000
76ab484
2bdc84d
9b15285
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,13 @@ | ||
public class Deadline extends Task{ | ||
|
||
String dueDate; | ||
public Deadline(String description, String dueDate) { | ||
super(description); | ||
this.dueDate = dueDate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (" + this.dueDate + ')'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,83 @@ | ||
import java.util.*; | ||
|
||
|
||
public class Duke { | ||
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("Hello! I'm Duke\n"); | ||
System.out.println("What can I do for you?\n"); | ||
|
||
List<Task> lst = new ArrayList<>(); | ||
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. Nice naming, easy to understand in subsequent code 👍 |
||
|
||
|
||
|
||
while (true) { | ||
try { | ||
String input = sc.nextLine().toLowerCase(); | ||
String[] inputArr = input.split(" ", 2); | ||
String action = inputArr[0]; | ||
|
||
if (action.equals("bye")) { | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
return; | ||
} else if (action.equals("list")) { // list | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int i = 1; i <= lst.size(); i++) { | ||
System.out.println(i + ". " + lst.get(i - 1)); | ||
} | ||
} else if (action.equals("mark")) { | ||
String details = inputArr[1]; | ||
int taskNum = Integer.parseInt(details); | ||
Task currTask = lst.get(taskNum - 1); | ||
currTask.mark(); | ||
System.out.println("Nice! I've marked this task as done" + '\n' + currTask); | ||
} else if (action.equals("unmark")) { | ||
String details = inputArr[1]; | ||
int taskNum = Integer.parseInt(details); | ||
Task currTask = lst.get(taskNum - 1); | ||
currTask.unMark(); | ||
System.out.println("Nice! I've marked this task as not done yet" + '\n' + currTask); | ||
} else if (action.equals("todo")) { | ||
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. Perhaps, using a switch-case statement would make it slightly more readable. |
||
String[] actionAndDetails = input.split(" ", 2); | ||
if (actionAndDetails.length == 1) { | ||
throw new DukeException("OOPS!!! The description of a todo cannot be empty."); | ||
} | ||
String details = actionAndDetails[1]; | ||
Todo newTodo = new Todo(details); | ||
lst.add(newTodo); | ||
System.out.println("Got it. I've added this task:" + '\n' + newTodo + '\n' + "Now you have " + lst.size() + " tasks in the 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. This line may be exceeding the 120 character limit, perhaps you would like to double check! |
||
} else if (action.equals("deadline")) { | ||
String[] detailsAndDate = inputArr[1].split(" /by "); | ||
String details = detailsAndDate[0]; | ||
String date = detailsAndDate[1]; | ||
Deadline newDeadline = new Deadline(details, date); | ||
lst.add(newDeadline); | ||
System.out.println("Got it. I've added this task:" + '\n' + newDeadline + '\n' + "Now you have " + lst.size() + " tasks in the list"); | ||
} else if (action.equals("event")) { | ||
String[] detailsAndTime = inputArr[1].split(" /from "); | ||
String details = detailsAndTime[0]; | ||
String[] Time = detailsAndTime[1].split(" /to "); | ||
String To = Time[0]; | ||
String From = Time[1]; | ||
Event newEvent = new Event(details, To, From); | ||
lst.add(newEvent); | ||
System.out.println("Got it. I've added this task:" + '\n' + newEvent + '\n' + "Now you have " + lst.size() + " tasks in the list"); | ||
} else if (action.equals("delete")) { | ||
String details = inputArr[1]; | ||
int taskNum = Integer.parseInt(details); | ||
Task currTask = lst.get(taskNum - 1); | ||
lst.remove(taskNum - 1); | ||
System.out.println("Noted. I've removed this task:" + '\n' + currTask + '\n' + "Now you have " + lst.size() + " tasks in the list"); | ||
}else { | ||
throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
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. Cute emoji 😄 |
||
} | ||
} catch (DukeException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
|
||
} | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class DukeException extends Exception{ | ||
|
||
public DukeException(String message) { | ||
super(message); | ||
} | ||
|
||
public String getMessage() { | ||
return super.getMessage(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Event extends Task { | ||
|
||
String From; | ||
String To; | ||
public Event(String description, String From, String To) { | ||
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. Perhaps, the naming of the fields can follow the norm of the 'description' field with small letters instead of capitalised ones. I think as long as you are consistent, it should be fine |
||
super(description); | ||
this.From = From; | ||
this.To = To; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (from: " + this.From + " to: " + this.To + ")"; | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.util.*; | ||
|
||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X": " "); | ||
} | ||
|
||
public String getDescription() { | ||
return this.description; | ||
} | ||
|
||
public void mark() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unMark() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + this.getStatusIcon() + "] " + this.description; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class Todo extends Task { | ||
|
||
public Todo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
Got it. I've added this task: | ||
[T][ ] borrow book | ||
Now you have 1 tasks in the list | ||
Here are the tasks in your list: | ||
1. [T][ ] borrow book | ||
Got it. I've added this task: | ||
[D][ ] return book (sunday) | ||
Now you have 2 tasks in the list | ||
Got it. I've added this task: | ||
[E][ ] project meeting (from: mon 2pm to: 4pm) | ||
Now you have 3 tasks in the list |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
todo borrow book | ||
list | ||
deadline return book /by Sunday | ||
event project meeting /from Mon 2pm /to 4pm | ||
|
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.
According to the coding standard, you may want to list all imports explicitly as they make the class easier to read 😀