-
Notifications
You must be signed in to change notification settings - Fork 270
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
[Brian Chow] iP #296
base: master
Are you sure you want to change the base?
[Brian Chow] iP #296
Changes from 8 commits
d839859
487213c
63bd8fe
63b7384
5188549
629d77c
62a2177
49d9e0a
89c0746
22f31af
a2b7ffd
3c16b7b
633dca6
38a2462
e129edd
cd020f5
6ace068
33617d4
6da11ff
ae099f5
390edec
2607baf
aca80eb
f97ff93
bb37f21
255fbef
b4458cc
3960ddc
9bd5f23
ee148e4
5344d8e
747cd67
fee4ebb
e1dec30
c126d99
133c672
5d7d4fb
87677f2
805ab54
effc8c7
5e3b5c9
9004041
4c29aa2
68e9fea
436be42
38d5c9a
56d537e
18b7995
ca00570
4460756
a58d8da
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,20 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
|
||
/** | ||
* Represents a Deadline which is a subclass of Task | ||
* Includes a dueDate attribute. Overrides toString() from Task | ||
*/ | ||
public class Deadline extends Task { | ||
private String dueDate; | ||
public Deadline(String name, String time) {super(name); this.dueDate = 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. Could leave spacing for better readability. |
||
|
||
/** | ||
* @override | ||
* @return String of Deadline task, eg [D][X] Deadline (by:XX) | ||
*/ | ||
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. Override should not be in the javadoc. Missing method's description for the javadoc.
|
||
|
||
public String toString() { return "[D]" + super.toString() + "(by:" + this.dueDate + ")"; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,40 @@ | ||
import java.util.Scanner; //import Scanner | ||
import java.util.ArrayList; //import ArrayList | ||
import java.util.Arrays; //import Arrays | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
String dukeGreeting = "Hello! I'm Duke \nWhat can I do for you?"; | ||
String endMessage = "Bye. Hope to see you again soon!"; | ||
|
||
System.out.println(dukeGreeting); | ||
Scanner sc = new Scanner(System.in); | ||
InputHandler inputHandler = new InputHandler(); | ||
boolean isChatEnded = false; | ||
while (!isChatEnded) { | ||
try { | ||
String input = sc.nextLine(); | ||
isChatEnded = inputHandler.handleInput(input); | ||
} catch (DukeException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
System.out.println(endMessage); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
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 clear by these empty spaces. 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. Agreed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class DukeException extends Exception{ | ||
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. Missing javadoc for class. |
||
private String errorMessage; | ||
public DukeException (String errorMessage) { | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
/** | ||
* @override | ||
* @return String errorMessage | ||
*/ | ||
public String getMessage() {return this.errorMessage;} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Represents a Event which is a subclass of Task | ||
* Overrides toString() from Task | ||
*/ | ||
public class Event extends Task { | ||
private String dueDate; | ||
public Event (String name, String time) { super(name); this.dueDate = 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. This do not follow the module coding standards. |
||
|
||
/** | ||
* @override | ||
* @return String of Event task, eg: [E][X] Event | ||
*/ | ||
public String toString() { return "[E]" + super.toString() + "(at:" + this.dueDate + ")"; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Handles input in main in Duke.java. Receives String from Scanner in main | ||
* Processes the input into 7 categories: Todo, Event, Deadline, list, mark, unmark, bye and throws error | ||
*/ | ||
public class InputHandler { | ||
private ArrayList<Task> arr; | ||
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. Might be better to have a more specific and plural name for a list of task.
|
||
public InputHandler() { | ||
this.arr = 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. Missing method description for javadoc. |
||
* @param input String input from main in Duke.java, from user input | ||
* @return boolean representing isChatEnded variable in main. If "bye" command is given, a true boolean is returned, else false is returned | ||
* @throws DukeException Invalid input types, or unrecognisable commands | ||
*/ | ||
public boolean handleInput(String input) throws DukeException { | ||
String[] splitInput = input.split(" "); | ||
String inputCommand = splitInput[0]; | ||
switch (inputCommand) { | ||
case "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. I didn't like the indentation after the switch, are you sure this complies with the coding standard? Consider leaving no indentation for the case statements. |
||
if (splitInput.length > 1) { | ||
String[] nameArray = Arrays.copyOfRange(splitInput, 1, splitInput.length); | ||
String name = String.join(" ", nameArray); | ||
Todo newTodo = new Todo(name); | ||
arr.add(newTodo); | ||
printAddTaskMessage(newTodo); | ||
return false; | ||
} else { | ||
throw new DukeException(":( OOPS!!! The description of a todo cannot be empty. Correct usage: todo [task]"); | ||
} | ||
case "event": | ||
if (splitInput.length > 3) { | ||
String[] stringArrayExcludingEvent = Arrays.copyOfRange(splitInput, 1, splitInput.length); | ||
String stringExcludingEvent = String.join(" ", stringArrayExcludingEvent); | ||
String[] nameAndTimeArray = stringExcludingEvent.split("/at"); | ||
String name = nameAndTimeArray[0]; | ||
String time = nameAndTimeArray[1]; | ||
Event newEvent = new Event(name, time); | ||
arr.add(newEvent); | ||
printAddTaskMessage(newEvent); | ||
return false; | ||
} else { | ||
throw new DukeException(":( OOPS!!! The description of a event cannot be empty. Correct usage: event [task] /at [time]"); | ||
} | ||
case "deadline": | ||
if (splitInput.length > 3) { | ||
String[] stringArrayExcludingDeadline = Arrays.copyOfRange(splitInput, 1, splitInput.length); | ||
String stringExcludingDeadline = String.join(" ", stringArrayExcludingDeadline); | ||
String[] nameAndTimeArray = stringExcludingDeadline.split("/by"); | ||
String name = nameAndTimeArray[0]; | ||
String time = nameAndTimeArray[1]; | ||
Deadline newDeadline = new Deadline(name, time); | ||
arr.add(newDeadline); | ||
printAddTaskMessage(newDeadline); | ||
return false; | ||
} else { | ||
throw new DukeException(":( OOPS!!! The description of a deadline cannot be empty. Correct usage: deadline [task] /by [time]"); | ||
} | ||
case "list": | ||
if (splitInput.length == 1) { | ||
System.out.println("Here are the tasks in your list:"); | ||
int i = 0; | ||
for (Task item : arr) { | ||
i += 1; | ||
if (item.isMark()) { | ||
System.out.println(i + ". " + item); | ||
} else { | ||
System.out.println(i + ". " + item); | ||
} | ||
} | ||
return false; | ||
} else { | ||
throw new DukeException("Wrong usage of list! Correct usage: list"); | ||
} | ||
case "mark": | ||
if (splitInput.length == 2) { | ||
System.out.println("Nice! I've marked this task as done:\n"); | ||
int idx = Integer.parseInt(splitInput[1]) - 1; | ||
Task taskToBeMarked = arr.get(idx); | ||
taskToBeMarked.markTask(); | ||
return false; | ||
} else { | ||
throw new DukeException("Wrong usage of mark! Correct usage: mark [index]"); | ||
} | ||
case "unmark": | ||
if (splitInput.length == 2) { | ||
System.out.println("OK, I've marked this task as not done yet:\n"); | ||
int idx = Integer.parseInt(splitInput[1]) - 1; | ||
Task taskToBeUnmarked = arr.get(idx); | ||
taskToBeUnmarked.unmarkTask(); | ||
return false; | ||
} else { | ||
throw new DukeException("Wrong usage of unmark! Correct usage: unmark [index]"); | ||
} | ||
case "delete": | ||
if (splitInput.length == 2) { | ||
int idx = Integer.parseInt(splitInput[1]) - 1; | ||
Task taskToBeDeleted = arr.get(idx); | ||
arr.remove(idx); | ||
System.out.println("Noted. I've removed this task:\n" + taskToBeDeleted + "\nNow you have " + arr.size() + " tasks in the list"); | ||
return false; | ||
} else { | ||
throw new DukeException("Wrong usage of delete! Correct usage: delete [index]"); | ||
} | ||
case "bye": | ||
return true; | ||
default: | ||
throw new DukeException(":( OOPS!!! I'm sorry, but I don't know what that means! Possible commands: todo [task], event [task] /at [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. Could add indentation. |
||
+ " deadline [task] /by [time], mark [index], unmark [index], delete [index], 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. This method severely exceeds the recommended number of lines in a method (30). |
||
|
||
} | ||
|
||
/** | ||
* Prints out the task name that has been added as well as the number of tasks in the list | ||
* @param task The task that has been added | ||
*/ | ||
public void printAddTaskMessage(Task task) { | ||
System.out.println("Got it. I've added this task:\n" + task + "\nNow you have " + arr.size() + " tasks in the list." ); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||
import java.util.Scanner; | ||||||
import java.util.ArrayList; | ||||||
import java.util.Arrays; | ||||||
|
||||||
/** | ||||||
* Represents a Task. Contains a Task constructor, two methods to mark and unmark tasks, toString() method as well as a isMark() method to check if Task is marked | ||||||
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 add indentation. |
||||||
*/ | ||||||
public class Task { | ||||||
private boolean 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. Not sure I like the naming of the boolean variable. As much as possible, use a prefix such as is, has, was, etc. for boolean variable/method names so that linters can automatically verify that this style rule is being followed. Perhaps it would be better to name it as follows?
Suggested change
|
||||||
public String name; | ||||||
|
||||||
/** | ||||||
* Constructor | ||||||
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. Might be better to have a more specific description of a constructor instead of simply "Constructor".
|
||||||
* @param name name of the task | ||||||
*/ | ||||||
public Task (String name) { | ||||||
this.name = name; | ||||||
this.mark = false; | ||||||
} | ||||||
|
||||||
/** | ||||||
* markTask as done | ||||||
*/ | ||||||
public void markTask () { | ||||||
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 this be named in this manner? Perhaps the following would comply with the coding standards better.
Suggested change
|
||||||
String markedMessage = "Nice! I've marked this task as done:\n"; | ||||||
this.mark = true; | ||||||
System.out.println(markedMessage + " " + this); | ||||||
} | ||||||
|
||||||
/** | ||||||
* unmarkTask | ||||||
*/ | ||||||
public void unmarkTask() { | ||||||
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 this be named in this manner? Perhaps the following would comply with the coding standards better.
Suggested change
|
||||||
String unmarkedMessage = "OK, I've marked this task as not done yet:\n"; | ||||||
this.mark = false; | ||||||
System.out.println(unmarkedMessage + " " + this); | ||||||
} | ||||||
|
||||||
/** | ||||||
* | ||||||
* @return boolean on whether task is marked | ||||||
*/ | ||||||
public boolean isMark() { | ||||||
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 this be changed to another name, if you do decide to accept the suggestion of the boolean variable naming? Perhaps the following would work.
Suggested change
|
||||||
return this.mark; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @override | ||||||
* @return String version of task, with marked and name. E.g. [X] Task | ||||||
*/ | ||||||
public String toString() { | ||||||
if (this.mark) { | ||||||
String marked = "[X] "; | ||||||
return marked + this.name; | ||||||
} else { | ||||||
String unmarked = "[ ] "; | ||||||
return unmarked + this.name; | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Represents a Todo which is a subclass of Task | ||
* Includes a dueDate attribute. Overrides toString() from Task | ||
*/ | ||
|
||
public class Todo extends Task { | ||
public Todo (String name) { | ||
super(name); | ||
} | ||
|
||
/** | ||
* @override | ||
* @return String of Todo task, eg: [T][X] Todo | ||
*/ | ||
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.
Missing javadocs for constructor.