-
Notifications
You must be signed in to change notification settings - Fork 228
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
[Jacob-109] iP #234
base: master
Are you sure you want to change the base?
[Jacob-109] iP #234
Changes from 12 commits
271e2f4
9522d74
082e99c
56d2f18
5b6adf0
0e6d2c7
b4d0ca6
91ba5b7
28f54b8
44c3b6d
81367c5
7e03915
3166da9
436656a
5a03f8f
5220f22
14de94b
0305fd6
9d38c53
76fb6d6
9337ccb
7301499
d7889df
bf4797e
05a3f62
c2d76ad
7d82d76
04b7f4d
f8c8bea
876e9ec
08f29a1
a82c13b
6cbdfba
4211cd9
afe7462
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; | ||
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 have a better convention such as dateTime. "by" alone doesn't have any meaning. 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. so sorry I thought this was my iP, please ignore my replies if any:) |
||
|
||
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,75 @@ | ||
import java.lang.reflect.Array; | ||
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 I check if this import is being used? Because Array should be present by default in Java. |
||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
public class Duke { | ||
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. Will it be better to add javadoc to all public classes and methods? The same applies to all other public classes and methods. |
||
public static void main(String[] args) { | ||
public static void main(String[] args) throws DukeException{ | ||
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 should catch the DukeException, if not your program would stop running due to the exception. |
||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
Scanner sc = new Scanner(System.in); | ||
ArrayList<Task> list = 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. Should be lists instead of list. Also, the naming convention could have been better, perhaps using tasks is better? After all, your code is being read by many people with different backgrounds. So it would be better if your naming convention is clearer. |
||
|
||
while(sc.hasNext()) { | ||
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. Will it be better to abstract and break this method into many smaller units? It will help in the future also. |
||
String word = sc.nextLine(); | ||
if (word.equals("bye")) { | ||
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 can change the if-else to switch case for better readability. |
||
System.out.println("Bye, hope to see you again!"); | ||
break; | ||
} else if (word.equals("list")) { | ||
int size = list.size(); | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int i = 1; i <= size; 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. Could have just do for (int i = 1; i <= list.size(); i++) |
||
System.out.println(i + ". " + list.get(i - 1).toString()); | ||
} | ||
} else if (word.contains("done")) { | ||
String strArray[] = word.split(" "); | ||
int value = Integer.parseInt(strArray[1]); | ||
Task complete = list.get(value - 1); | ||
complete.markAsDone(); | ||
System.out.println(" Nice! I've marked this task as done: "); | ||
System.out.println(complete.toString()); | ||
} else if (word.contains("delete")) { | ||
String arr[] = word.split(" "); | ||
int value = Integer.parseInt(arr[1]); | ||
Task remove = list.get(value - 1); | ||
list.remove(value - 1); | ||
System.out.println("Noted. I've removed this task: "); | ||
System.out.println(remove.toString()); | ||
System.out.println("Now you have " + list.size() + " tasks in the list"); | ||
} else if ((word.contains("todo")) || (word.contains("event")) || (word.contains("deadline"))) { | ||
if (word.contains("todo")) { | ||
String save = word.replaceAll("todo",""); | ||
ToDo t = new ToDo(save); | ||
if (save.equals("")) { | ||
Thread.setDefaultUncaughtExceptionHandler((u, e) -> System.err.println(e.getMessage())); | ||
throw new DukeException("OOPS!!! The description of a todo cannot be empty."); | ||
} | ||
list.add(t); | ||
System.out.println("Got it. I've added this task: "); | ||
System.out.println(t.toString()); | ||
} else if (word.contains("event")) { | ||
String[] info = word.split("/at"); | ||
info[0] = info[0].replaceAll("event",""); | ||
Event e = new Event(info[0],info[1]); | ||
list.add(e); | ||
System.out.println("Got it. I've added this task: "); | ||
System.out.println(e.toString()); | ||
} else if (word.contains("deadline")) { | ||
String[] input = word.split("/by"); | ||
input[0] = input[0].replaceAll("deadline", ""); | ||
Deadline d = new Deadline(input[0], input[1]); | ||
list.add(d); | ||
System.out.println("Got it. I've added this task: "); | ||
System.out.println(d.toString()); | ||
} | ||
System.out.println("Now you have " + list.size() + " tasks in the list"); | ||
} else { | ||
Thread.setDefaultUncaughtExceptionHandler((u, e) -> System.err.println(e.getMessage())); | ||
throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
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 datetime; | ||
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. Your deadline by naming convention should have followed this format as well. |
||
|
||
public Event(String description, String datetime) { | ||
super(description); | ||
this.datetime = datetime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (at: " + datetime + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
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. It seems like getStatusIcon() is used in this task class only, hence you can change public to private. |
||
if (isDone) { | ||
return "Done"; | ||
} else { | ||
return "Incompleted";// unsure why tick and cross did not show as intended | ||
// hence the change to Done and Incompleted. | ||
} | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
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(); | ||
} | ||
} |
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.
Should the class be added or grouped inside a package? This applies to other classes as well.