Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,30 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
```

## How to use

The commands this program uses are; `todo`, `deadline`, `event`, `list`, `mark`, `find`, `delete` and `bye`**
`todo`, `deadline` and `event` are the different types of tasks you can add into your list to keep track of.

1. `todo`s are the simplest task to add as they do not require you to add in a start/end time, only a description of the task
e.g. `todo lunch`

2. `deadline`s, as the name suggests, are tasks which have a deadline. The due date or time is indicated after a `/`
e.g. `lunch/12pm`

3. `event`s are tasks which have a duration, from a start time to an end time
e.g. `lunch/12pm/1pm

4. `list` shows you the tasks which you have added. You can view them by simply typing `list`

5. `mark` checks off the task which you have completed.
e.g. `mark 3`

6. `find` searches your list of tasks to find those which have a certain ketword present.
e.g. `find lunch`

7. `delete` removes one of the tasks in your list
e.g. `delete 2`

Finally, `bye` allows you the exit program
2 changes: 2 additions & 0 deletions src/main/java/AddTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class AddTask {
}
2 changes: 2 additions & 0 deletions src/main/java/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class ByeCommand {
}
13 changes: 13 additions & 0 deletions src/main/java/Deadline.java
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 + ")";
}
}
2 changes: 2 additions & 0 deletions src/main/java/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class DeleteCommand {
}
2 changes: 2 additions & 0 deletions src/main/java/DisplayMessages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class DisplayMessages {
}
180 changes: 175 additions & 5 deletions src/main/java/Duke.java
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];
Copy link

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.

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)) {
Copy link

Choose a reason for hiding this comment

The 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]);
Copy link

Choose a reason for hiding this comment

The 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);
}
}
15 changes: 15 additions & 0 deletions src/main/java/Event.java
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 + ")";
}
}
2 changes: 2 additions & 0 deletions src/main/java/InvalidCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class InvalidCommandException extends Exception {
}
3 changes: 3 additions & 0 deletions src/main/java/ListCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class ListCommand {

}
3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Duke

2 changes: 2 additions & 0 deletions src/main/java/MarkCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class MarkCommand {
}
22 changes: 22 additions & 0 deletions src/main/java/Parser.java
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":

}
}
}
25 changes: 25 additions & 0 deletions src/main/java/Task.java
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
Copy link

Choose a reason for hiding this comment

The 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;
}
}
11 changes: 11 additions & 0 deletions src/main/java/ToDo.java
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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, strings like [T] can be seen as a magic strings. You might want to consider extracting strings like this into a named constants. Sometimes, you could also use enums to achieve similar effect. There could be other magic strings/numbers/literals in your other code too that you might want to look out for them.

}
}
4 changes: 4 additions & 0 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Ui {


}
2 changes: 2 additions & 0 deletions src/main/java/UnmarkCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class UnmarkCommand {
}