-
Notifications
You must be signed in to change notification settings - Fork 200
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
[Lee Zhi Zhong Moses] iP #227
base: master
Are you sure you want to change the base?
Changes from all commits
9f810e6
dccfb91
a5f952e
a60298c
3262052
72c59ce
3242102
2fbc568
07bc4d5
f35b087
f4e64e5
5fbe514
11fed99
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,2 @@ | ||
public class AddTask { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class ByeCommand { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Deadline extends Task{ | ||
protected String dueDate; | ||
|
||
public Deadline(String description, String dueBy) { | ||
super(description); | ||
this.dueDate = dueBy; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (due by: " + dueDate + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class DeleteCommand { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class DisplayMessages { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,180 @@ | ||
import java.util.Scanner; | ||
import java.util.Arrays; | ||
public class Duke { | ||
|
||
private static Scanner in = new Scanner(System.in); | ||
private static final Task[] tasks = new Task[100]; | ||
private static final Task[] foundTasks = new Task[100]; | ||
|
||
public static void whatToDo(String line) { | ||
try { | ||
command(line); | ||
} | ||
catch (InvalidCommandException error) { | ||
System.out.println("Try using one of following commands: todo, deadline, event."); | ||
line = in.nextLine(); | ||
whatToDo(line); | ||
} | ||
catch (IndexOutOfBoundsException error) { | ||
System.out.println("Oops! You need to provide a description/time for your task"); | ||
line = in.nextLine(); | ||
whatToDo(line); | ||
} | ||
} | ||
|
||
public static boolean isWordPresent(Task task, String keyword) { | ||
String[] words = (task.description).split(" "); | ||
|
||
for (String temp : words) { | ||
if (temp.compareToIgnoreCase(keyword) == 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static void command(String line) throws InvalidCommandException { | ||
String exitCommand = "bye"; | ||
String taskList = "list"; | ||
String checkAsDone = "mark"; | ||
String del = "delete"; | ||
String search = "find"; | ||
int numberOfTasks = 0; | ||
|
||
String[] tokens = line.split(" ", 2); | ||
String command = tokens[0]; | ||
|
||
while (!command.equals(exitCommand)) { | ||
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. Currently, this entire method is too long. You can try to keep a method short by extracting its content out to other methods whenever appropriate. |
||
if (tokens[0].equals(taskList)) { | ||
System.out.println("Here are your list of tasks to complete!"); | ||
for (int i = 0; i < numberOfTasks; ++i) { | ||
System.out.format("%d. ", (i + 1)); | ||
System.out.println(tasks[i]); | ||
} | ||
line = in.nextLine(); | ||
tokens = line.split(" ", 2); | ||
command = tokens[0]; | ||
} else if (command.equals(checkAsDone)){ | ||
int finishedTask = Integer.parseInt(tokens[1]) - 1; | ||
tasks[finishedTask].markDone(); | ||
System.out.println("Alright! I have marked the task as complete!"); | ||
|
||
for (int i = 0; i < numberOfTasks; ++i) { | ||
System.out.format("%d. ", (i + 1)); | ||
System.out.println(tasks[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. This is a good use of polymorphism here. You can apply a similar concept when dealing with similar scenarios in further levels. |
||
} | ||
|
||
line = in.nextLine(); | ||
tokens = line.split(" ", 0); | ||
command = tokens[0]; | ||
} else if (command.equals(del)) { | ||
int taskToDelete = Integer.parseInt(tokens[1]) - 1; | ||
for (int i = taskToDelete; i < (tasks.length - 1); ++i) { | ||
tasks[i] = tasks[i + 1]; | ||
} | ||
--numberOfTasks; | ||
System.out.println("Removed task number " + (taskToDelete + 1) + ". Here are your remaining tasks:"); | ||
for (int i = 0; i < numberOfTasks; ++i) { | ||
System.out.format("%d. ", (i + 1)); | ||
System.out.println(tasks[i]); | ||
} | ||
|
||
line = in.nextLine(); | ||
tokens = line.split(" ", 0); | ||
command = tokens[0]; | ||
} else if (command.equals(search)) { | ||
String itemToFind = tokens[1]; | ||
int searchNumber = 0; | ||
|
||
for (int i = 0; i < numberOfTasks; ++i) { | ||
if (isWordPresent(tasks[i], itemToFind)) { | ||
foundTasks[searchNumber] = tasks[i]; | ||
searchNumber++; | ||
} | ||
} | ||
System.out.println("Tasks matching with " + itemToFind); | ||
for (int i = 0; i < searchNumber; ++i) { | ||
System.out.format("%d. ", (i + 1)); | ||
System.out.println(foundTasks[i]); | ||
} | ||
|
||
line = in.nextLine(); | ||
tokens = line.split(" ", 0); | ||
command = tokens[0]; | ||
} else { | ||
String task = tokens[1]; | ||
switch(command) { | ||
case "todo": | ||
Task t = new ToDo(task); | ||
tasks[numberOfTasks] = t; | ||
tasks[numberOfTasks].isDone = false; | ||
++numberOfTasks; | ||
break; | ||
case "deadline": | ||
String[] taskDeadline = task.split("/", 2); | ||
String taskDescription = taskDeadline[0]; | ||
String dueBy = taskDeadline[1]; | ||
|
||
Task d = new Deadline(taskDescription, dueBy); | ||
tasks[numberOfTasks] = d; | ||
tasks[numberOfTasks].isDone = false; | ||
++numberOfTasks; | ||
break; | ||
case "event": | ||
String[] taskEvent = task.split("/", 3); | ||
String eventDescription = taskEvent[0]; | ||
String start = taskEvent[1]; | ||
String end = taskEvent[2]; | ||
|
||
Task e = new Event(eventDescription, start, end); | ||
tasks[numberOfTasks] = e; | ||
tasks[numberOfTasks].isDone = false; | ||
++numberOfTasks; | ||
break; | ||
default: | ||
System.out.println("Sorry! I couldn't understand your command:( Please try again."); | ||
throw new InvalidCommandException(); | ||
} | ||
System.out.println("added: " + line); | ||
line = in.nextLine(); | ||
tokens = line.split(" ", 0); | ||
command = tokens[0]; | ||
} | ||
} | ||
System.out.println("Bye! Hope to see you again"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
String logo = " ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡟⠋⠈⠙⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠤⢤⡀⠀⠀\n" + | ||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠈⢇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠞⠀⠀⢠⡜⣦⠀\n" + | ||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡃⠀⠀⠀⠀⠈⢷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⣠⠀⠀⠀⠀⢻⡘⡇\n" + | ||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠙⢶⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡠⠚⢀⡼⠃⠀⠀⠀⠀⠸⣇⢳\n" + | ||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⠀⣀⠖⠀⠀⠀⠀⠉⠀⠀⠈⠉⠛⠛⡛⢛⠛⢳⡶⠖⠋⠀⢠⡞⠀⠀⠀⠐⠆⠀⠀⣿⢸\n" + | ||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣦⣀⣴⡟⠀⠀⢶⣶⣾⡿⠀⠀⣿⢸\n" + | ||
"⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⡠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣏⠀⠀⠀⣶⣿⣿⡇⠀⠀⢏⡞\n" + | ||
"⠀⠀⠀⠀⠀⠀⢀⡴⠛⠀⠀⠀⠀⠀⠀⠀⠀⢀⢀⡾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢦⣤⣾⣿⣿⠋⠀⠀⡀⣾⠁\n" + | ||
"⠀⠀⠀⠀⠀⣠⠟⠁⠀⠀⠀⣀⠀⠀⠀⠀⢀⡟⠈⢀⣤⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⣏⡁⠀⠐⠚⠃⣿⠀\n" + | ||
"⠀⠀⠀⠀⣴⠋⠀⠀⠀⡴⣿⣿⡟⣷⠀⠀⠊⠀⠴⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠀⠀⠀⠀⢹⡆\n" + | ||
"⠀⠀⠀⣴⠃⠀⠀⠀⠀⣇⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⡶⢶⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇\n" + | ||
"⠀⠀⣸⠃⠀⠀⠀⢠⠀⠊⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⢲⣾⣿⡏⣾⣿⣿⣿⣿⠖⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢧\n" + | ||
"⠀⢠⡇⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠈⠛⠿⣽⣿⡿⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜\n" + | ||
"⢀⡿⠀⠀⠀⠀⢀⣤⣶⣟⣶⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇\n" + | ||
"⢸⠇⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇\n" + | ||
"⣼⠀⢀⡀⠀⠀⢷⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡇\n" + | ||
"⡇⠀⠈⠀⠀⠀⣬⠻⣿⣿⣿⡿⠙⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁\n" + | ||
"⢹⡀⠀⠀⠀⠈⣿⣶⣿⣿⣝⡛⢳⠭⠍⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠃⠀\n" + | ||
"⠸⡇⠀⠀⠀⠀⠙⣿⣿⣿⣿⣿⣿⣷⣦⣀⣀⣀⣤⣤⣴⡶⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠇⠀⠀\n" + | ||
"⠀⢿⡄⠀⠀⠀⠀⠀⠙⣇⠉⠉⠙⠛⠻⠟⠛⠛⠉⠙⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠋⠀⠀⠀\n" + | ||
"⠀⠈⢧⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠁⠀⠀⠀⠀\n" + | ||
"⠀⠀⠘⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠁⠀⠀⠀⠀⠀⠀\n" + | ||
"⠀⠀⠀⠀⠱⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡴⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀\n" + | ||
"⠀⠀⠀⠀⠀⠀⠛⢦⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⠴⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" + | ||
"⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠲⠤⣤⣤⣤⣄⠀⠀⠀⠀⠀⠀⠀⢠⣤⣤⠤⠴⠒⠛⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀"; | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println("Hi! My name is Doge. \n Nice to meet you!"); | ||
|
||
String line; | ||
line = in.nextLine(); | ||
whatToDo(line); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Event extends Task{ | ||
protected String start; | ||
protected String end; | ||
|
||
public Event(String description, String start, String end) { | ||
super(description); | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (from: " + start + " to " + end + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class InvalidCommandException extends Exception { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public class ListCommand { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: Duke | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class MarkCommand { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
public class Parser { | ||
|
||
String command; | ||
String taskDescription; | ||
String deadline; | ||
String startDate; | ||
String endDate; | ||
String taskNumber; | ||
boolean shouldQuit = false; | ||
|
||
|
||
public Parser (String userInput) { | ||
String[] tokens = userInput.split(" "); | ||
command = tokens[0]; | ||
|
||
switch(command) { | ||
case "list": | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatus() { | ||
return (isDone ? "[X]" : "[ ]"); // mark done task with X | ||
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 might want to capitalise the first character in your comment. |
||
} | ||
|
||
public void markDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmarkDone() { | ||
this.isDone = false; | ||
} | ||
|
||
public String toString() { | ||
return getStatus() + " " + 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 commentThe reason will be displayed to describe this comment to others. Learn more. Arguably, strings like |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public class Ui { | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class UnmarkCommand { | ||
} |
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.
For program scalability, you might want to consider using
ArrayList
instead of setting a maximum number of tasks user can have here.