-
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
[iapetusbob] iP #385
base: master
Are you sure you want to change the base?
[iapetusbob] iP #385
Changes from 5 commits
556af3f
106e38e
415a967
48aff3a
1368b37
d21bb6e
1bc4747
dff68ac
b6de93c
aca63fa
b8ea184
be1870f
871d399
1200509
18fa619
01503ed
8e458d8
6a711f4
dd7e692
2ddf308
b1cb5a1
6fd1a4a
fb02add
f61a7bc
70e7de6
f4571a2
2085c41
849b2f2
86e7a1b
a1a0df9
8b60111
fdc1e3a
bb0e340
cd0cdf7
8b39140
f292f45
a1926cb
29bb3f4
2cc7f63
b293347
3e90bf7
6164973
27a0ec7
da35a31
6d6ffd5
f416d54
944c856
7a83d29
3efbfac
e6529b1
77f7e42
00a2151
f4deb72
1023e23
e1967ba
2bc8be0
f7a334c
1fb6fe7
20642d9
bae5a96
22ea094
b79fc3d
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 |
---|---|---|
@@ -1,10 +1,188 @@ | ||
import java.util.Scanner; | ||
import java.util.Arrays; | ||
import DukeHelpfulCode.*; | ||
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. Package name should also be in all lower case to meet coding standards. |
||
|
||
|
||
public class Duke { | ||
|
||
private static String LINEBREAK = "_________________________________________________________________\n"; | ||
private static UserList USERLIST = new UserList(); | ||
|
||
public static void main(String[] args) { | ||
greeting(); | ||
takeCmd(); | ||
} | ||
|
||
private static void takeCmd() { | ||
/** | ||
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. detailed JavaDoc comment that tells others what each command does. However, JavaDoc comment should be outside and above the function to meet coding standards. Is it possible to separate the code into smaller functions that will be called? This makes that code looks cleaner. |
||
* Controls flow, logic, checking of the user inputs as commands. | ||
* Recognized user commands: | ||
* bye -> quit | ||
* todo -> creates todo task | ||
* deadline-> creates deadline task | ||
* event -> creates event task | ||
* list -> display | ||
* mark -> marks the (i-1)th item as done, since UserList is 0-index | ||
* unmark -> unmarks the (i-1)th item | ||
* Unrecognized commands will simply be echoed then Duke waits next command. | ||
*/ | ||
Scanner userCmd = new Scanner(System.in); | ||
String askForCmd = LINEBREAK + "Okay. What would you like to do next?\nIf you want to exit DUKE, type 'bye'!\n"; | ||
String[] cmd = userCmd.nextLine().split(" "); | ||
if (cmd[0].equals("bye")) { | ||
exit(); | ||
} else if (cmd[0].equals("todo")) { | ||
String taskName = ""; | ||
if (cmd.length>1) { | ||
for (int i = 1; i < cmd.length; i++) { | ||
taskName += cmd[i] + " "; | ||
} | ||
} else { | ||
System.out.println("Sorry, I didn't quite catch that. What task would you like to add?\n" + LINEBREAK); | ||
taskName = userCmd.nextLine(); | ||
} | ||
addTodo(new Todo(taskName)); | ||
System.out.println(askForCmd); | ||
takeCmd(); | ||
} else if (cmd[0].equals("deadline")){ | ||
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 want to split commands into seperate functions |
||
String taskName = ""; | ||
String dateTime = ""; | ||
if (cmd.length>1) { | ||
for (int i = 1; i < cmd.length; i++) { | ||
if (!cmd[i].equals("/by")){ | ||
taskName += cmd[i] + " "; | ||
} else { | ||
i++; | ||
dateTime += cmd[i] + " "; | ||
} | ||
} | ||
} else { | ||
System.out.println("Sorry, I didn't quite catch that. What task would you like to add?\n" + LINEBREAK); | ||
cmd = userCmd.nextLine().split(" "); | ||
for (int i = 0; i < cmd.length; i++) { | ||
if (!cmd[i].equals("/by")){ | ||
taskName += cmd[i] + " "; | ||
} else { | ||
i++; | ||
dateTime += cmd[i] + " "; | ||
} | ||
} | ||
} | ||
addDeadline(new Deadline(taskName, dateTime)); | ||
System.out.println(askForCmd); | ||
takeCmd(); | ||
} else if (cmd[0].equals("event")){ | ||
String taskName = ""; | ||
String startDateTime = ""; | ||
String endDateTime = ""; | ||
if (cmd.length > 1) { | ||
int from = Arrays.asList(cmd).indexOf("/from"); | ||
int to = Arrays.asList(cmd).indexOf("/to"); | ||
for (int i = 1; i < cmd.length; i++){ | ||
if (i < from) { | ||
taskName += cmd[i] + " "; | ||
} else if (i > from && i < to){ | ||
startDateTime += cmd[i] + " "; | ||
} else if (i > to){ | ||
endDateTime += cmd[i] + " "; | ||
} | ||
} | ||
} else { | ||
System.out.println("Sorry, I didn't quite catch that. What task would you like to add?\n" + LINEBREAK); | ||
cmd = userCmd.nextLine().split(" "); | ||
int from = Arrays.asList(cmd).indexOf("/from"); | ||
int to = Arrays.asList(cmd).indexOf("/to"); | ||
for (int i = 0; i < cmd.length; i++){ | ||
if (i < from) { | ||
taskName += cmd[i] + " "; | ||
} else if (i > from && i < to){ | ||
startDateTime += cmd[i] + " "; | ||
} else if (i > to){ | ||
endDateTime += cmd[i] + " "; | ||
} | ||
} | ||
} | ||
addEvent(new Event(taskName, startDateTime, endDateTime)); | ||
System.out.println(askForCmd); | ||
takeCmd(); | ||
} else if (cmd[0].equals("list")){ | ||
list(); | ||
System.out.println(askForCmd); | ||
takeCmd(); | ||
} else if (cmd[0].equals("mark") || cmd[0].equals("unmark")) { | ||
String markUnmark = cmd[0]; | ||
if (userCmd.hasNext()) { | ||
try { | ||
int listIdx = Integer.parseInt(userCmd.next()); | ||
mark(markUnmark, listIdx); | ||
System.out.println(askForCmd); | ||
takeCmd(); | ||
} catch (NumberFormatException e) { | ||
System.out.println("Sorry, I don't understand what you want to me to do.\n" + askForCmd); | ||
takeCmd(); | ||
} | ||
} else { | ||
System.out.println("Sorry, I don't understand what you want to me to do.\n" + askForCmd); | ||
takeCmd(); | ||
} | ||
} else { | ||
System.out.println(askForCmd); | ||
takeCmd(); | ||
} | ||
} | ||
|
||
private static void greeting() { | ||
/** | ||
* Start-up logo and message | ||
*/ | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println("Hello from\n" + logo + LINEBREAK + "Type 'bye' to exit!\n" + LINEBREAK + "What can I do for you today?\n"); | ||
} | ||
|
||
private static void exit() { | ||
/** | ||
* Exits Duke. | ||
* userCmd "bye" | ||
*/ | ||
System.out.println("Bye. Hope to see you again soon!\n" + LINEBREAK); | ||
} | ||
|
||
private static void addTodo(Todo todo){ | ||
USERLIST.addToDo(todo); | ||
} | ||
|
||
private static void addDeadline(Deadline dl){ | ||
USERLIST.addDeadline(dl); | ||
} | ||
|
||
private static void addEvent(Event e){ | ||
USERLIST.addEvent(e); | ||
} | ||
|
||
private static void list(){ | ||
/** | ||
* userCmd "list" | ||
* Displays userList vertically. | ||
*/ | ||
if (USERLIST.len() == 0){ | ||
System.out.println(LINEBREAK + "Oops, it seems that your list is empty!\n"); | ||
} else { | ||
System.out.println(LINEBREAK + "Your list looks like this:\n" + USERLIST.toString() + LINEBREAK); | ||
} | ||
} | ||
|
||
private static void mark(String markCmd, int idx){ | ||
try { | ||
USERLIST.mark(markCmd, idx); | ||
} catch (UserList.TaskNotInListException e) { | ||
System.out.println("Sorry, can't find that task.\n"); | ||
} catch (UserList.TaskAlrMarkException e){ | ||
System.out.println("The Task has already been marked.\n"); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package DukeHelpfulCode; | ||
|
||
public class Deadline extends Task{ | ||
// tasks that need to be done before a specific date/time | ||
private String dateTime; | ||
|
||
public Deadline(String name, String dateTime) { | ||
super(name); | ||
this.dateTime = dateTime; | ||
} | ||
|
||
public String toString(){ | ||
return "[D] " + super.toString() + " (by: " + this.dateTime + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package DukeHelpfulCode; | ||
|
||
public class Event extends Task{ | ||
// tasks that start at a specific date/time and ends at a specific date/time | ||
|
||
private String startDateTime; | ||
private String endDateTime; | ||
|
||
public Event(String name, String startDateTime, String endDateTime) { | ||
super(name); | ||
this.startDateTime = startDateTime; | ||
this.endDateTime = endDateTime; | ||
} | ||
|
||
public String toString() { | ||
return "[E] " + super.toString() + " (from: " + this.startDateTime + " to: " + this.endDateTime + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package DukeHelpfulCode; | ||
|
||
public class Task { | ||
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. JavaDoc for classes should also be outside and above the class itself. |
||
/** | ||
* Task class for things added to the UserList | ||
* Methods: | ||
* markAsDone -> mark Task as done if not done and vice versa. | ||
*/ | ||
|
||
private static String LINEBREAK = "_________________________________________________________________\n"; | ||
private String name; | ||
private Boolean isDone = false; | ||
|
||
public Task (String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public boolean isDone(){ | ||
return isDone; | ||
} | ||
|
||
public String toString() { | ||
/** | ||
* Returns "[done] Task" | ||
*/ | ||
char doneX = ' '; | ||
if (isDone) { | ||
doneX = 'X'; | ||
} | ||
return "[" + doneX + "]" + " " + name; | ||
} | ||
|
||
public boolean equals(Object obj){ | ||
if (obj instanceof Task) { | ||
Task objTask = (Task) obj; | ||
return objTask.name.equals(this.name); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public void mark() { | ||
/** | ||
* Marks Task as done if not done and vice versa. | ||
*/ | ||
if (isDone) { | ||
System.out.println(LINEBREAK + "OK, '" + this.name + "' has been marked as Not Done.\n"); | ||
isDone = false; | ||
} else { | ||
System.out.println(LINEBREAK + "OK, '" + this.name + "' has been marked as Done.\n"); | ||
isDone = true; | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package DukeHelpfulCode; | ||
|
||
public class Todo extends Task{ | ||
// tasks without any date/time atached to it | ||
public Todo(String name) { | ||
super(name); | ||
} | ||
|
||
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.
Perhaps you can ensure import classes are stated explicitly to meet coding standards.
Eg. import DukeHelpfulCode.Task;