-
Notifications
You must be signed in to change notification settings - Fork 462
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
[Gavin Cho] iP #530
base: master
Are you sure you want to change the base?
[Gavin Cho] iP #530
Changes from 9 commits
556af3f
1c74c0b
acab8ca
495d75f
cf2222b
f7da0fc
6efa017
f485a40
9ea2336
d1eeead
1bc98d4
d4c0930
77784ad
9f18cfa
7e0f15e
11ed975
9b80d78
6a229ea
577792e
9f8c006
6f73e7f
bb5a7ef
84d9b6f
6c36b7c
aee7f8a
cd63ed5
ed5372d
4bf0b8c
66485b3
ebdccba
a8245a2
b98175d
3301a16
b51074a
117aec7
76c94ea
4187f78
8c4e65a
70e51df
9ee19c5
bc5e274
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 { | ||
|
||
protected String by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,130 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
|
||
public Task[] tasks; | ||
|
||
|
||
public static void main(String[] args) throws DukeException { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
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. Perhaps the line break could be stored in a constant since it is used multiple times in the code |
||
System.out.println("Hello! I'm Duke\n What can I do for you?"); | ||
System.out.println("___________________________________"); | ||
|
||
Task[] tasks = new Task[100]; | ||
int counter = 0; | ||
ArrayList<Task> collection = new ArrayList<>(); | ||
|
||
Scanner sc = new Scanner(System.in); | ||
String input = sc.nextLine(); | ||
|
||
|
||
|
||
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 it might be better if there was only a single blank line here |
||
while (!input.equals("bye")) { | ||
if (input.equals("list")) { | ||
System.out.println("___________________________________"); | ||
for (int i = 0; i < counter; i++) { | ||
System.out.println( (i+1) + "." | ||
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. Seems like there's an extra whitespace on this line, might need to remove it to follow the coding standards |
||
+ collection.get(i).toString()); | ||
} | ||
System.out.println("___________________________________"); | ||
input = sc.next(); | ||
|
||
} | ||
|
||
else if (input.equals("mark")) { | ||
int number = sc.nextInt(); | ||
collection.get(number-1).mark(); | ||
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. Similar issue on missing/extra whitespaces, noticed this issue in several other places too, might have to address these to follow the coding standards |
||
System.out.println("___________________________________"); | ||
System.out.println("Nice! I've marked this task done: " + "\n" | ||
+ "[" + collection.get(number-1).getStatusIcon() + "] " + | ||
collection.get(number-1).description); | ||
System.out.println("___________________________________"); | ||
input = sc.next(); | ||
} | ||
|
||
else if (input.equals("unmark")) { | ||
int number = sc.nextInt(); | ||
collection.get(number-1).unmark(); | ||
System.out.println("___________________________________"); | ||
System.out.println("OK, I've marked this task as not done yet: " + "\n" | ||
+ "[" + collection.get(number-1).getStatusIcon() + "] " + | ||
collection.get(number-1).description); | ||
System.out.println("___________________________________"); | ||
input = sc.next(); | ||
} | ||
|
||
else if (input.equals("deadline")) { | ||
String what = sc.nextLine(); | ||
if (what.equals("")) throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty."); | ||
String byWhen = sc.nextLine(); | ||
collection.add(new Deadline(what, byWhen)); | ||
System.out.println("___________________________________"); | ||
System.out.println("Got it. I've added this task:" + "\n" | ||
+ " " + collection.get(counter).toString() + "\n" | ||
+ "Now you have " + (counter+1) + " tasks in the list."); | ||
System.out.println("___________________________________"); | ||
counter++; | ||
input = sc.nextLine(); | ||
} | ||
|
||
else if (input.equals("todo")) { | ||
String what = sc.nextLine(); | ||
if (what.equals("")) throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty."); | ||
collection.add(new Todo(what)); | ||
System.out.println("___________________________________"); | ||
System.out.println("Got it. I've added this task:" + "\n" | ||
+ " " + collection.get(counter).toString() + "\n" | ||
+ "Now you have " + (counter+1) + " tasks in the list."); | ||
System.out.println("___________________________________"); | ||
counter++; | ||
input = sc.nextLine(); | ||
} | ||
|
||
else if (input.equals("event")) { | ||
String what = sc.nextLine(); | ||
if (what.equals("")) throw new DukeException("☹ OOPS!!! The description of a event cannot be empty."); | ||
String atWhen = sc.nextLine(); | ||
collection.add(new Event(what, atWhen)); | ||
System.out.println("___________________________________"); | ||
System.out.println("Got it. I've added this task:" + "\n" | ||
+ " " + collection.get(counter).toString() + "\n" | ||
+ "Now you have " + (counter+1) + " tasks in the list."); | ||
System.out.println("___________________________________"); | ||
counter++; | ||
input = sc.nextLine(); | ||
} | ||
|
||
else if (input.equals("delete")) { | ||
int number = sc.nextInt(); | ||
Task temp = collection.get(number-1); | ||
collection.remove(number-1); | ||
counter--; | ||
System.out.println("___________________________________"); | ||
System.out.println("Noted. I've removed this task:" + "\n" | ||
+ " " + temp.toString() + "\n" | ||
+ "Now you have " + counter + " tasks in the list."); | ||
System.out.println("___________________________________"); | ||
input = sc.next(); | ||
|
||
} | ||
|
||
else { | ||
System.out.println("___________________________________"); | ||
throw new DukeException(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
|
||
} | ||
|
||
} | ||
|
||
System.out.println("___________________________________"); | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
System.out.println("___________________________________"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class DukeException extends Exception { | ||
|
||
public DukeException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Event extends Task{ | ||
|
||
protected String at; | ||
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. Maybe you can change the variable name from "at" to "eventTime" so that it sounds more meaningful? |
||
|
||
public Event(String description, String at) { | ||
super(description); | ||
this.at = at; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (at: " + at + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
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 following the coding standards for naming boolean variables👍 |
||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public void mark() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmark() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + this.getStatusIcon() + "] " + description; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class Todo extends Task { | ||
|
||
public Todo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
|
||
} |
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.
I think it might be better if the String had a more descriptive name, perhaps something like "date" or "deadline"?