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

[Kairos Koh] iP #189

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
98e53ab
Add Level 0. Greet (greets user and exits)
kairoskoh Aug 19, 2021
e0d5c4d
Add Level 1. Greet, Echo, Exit
kairoskoh Aug 25, 2021
ca6b0fe
Add Level-2. Add, List
kairoskoh Aug 25, 2021
13d9a37
Add Task.java
kairoskoh Aug 25, 2021
9dcbc95
Add Level 3. Mark as Done
kairoskoh Aug 25, 2021
c3d9af5
Add fixes to some exception inputs
kairoskoh Aug 25, 2021
72f7593
Add Deadline.java
kairoskoh Sep 1, 2021
1e289bf
Add Level 4. ToDos, Events, Deadlines
kairoskoh Sep 1, 2021
7b50777
Improve Code Quality
kairoskoh Sep 1, 2021
af71eb3
Add IllegalTaskException.java
kairoskoh Sep 8, 2021
6c57ecf
Add duke package
kairoskoh Sep 8, 2021
e8d8f41
Add Level 6. Delete and A-Collections
kairoskoh Sep 15, 2021
11315c6
Add DukeTaskData.txt
kairoskoh Sep 15, 2021
7c26728
Add minor changes to error message
kairoskoh Sep 15, 2021
3cf54db
Add minimal OOP classes
kairoskoh Sep 29, 2021
15d6adf
Make the code more OOP
kairoskoh Sep 29, 2021
57d09ac
Add file to ignore
kairoskoh Sep 29, 2021
eac25f9
Add function to find a task by searching for a keyword
kairoskoh Sep 29, 2021
c41f3af
Add JavaDoc
kairoskoh Sep 29, 2021
b8098ba
Add find functions
kairoskoh Sep 29, 2021
dfb01a0
Merge pull request #1 from kairoskoh/branch-Level-9
kairoskoh Sep 29, 2021
972d782
Add JavaDoc
kairoskoh Sep 29, 2021
663b585
Merge pull request #2 from kairoskoh/branch-A-JavaDoc
kairoskoh Sep 29, 2021
e41e1f4
Add Level 5
kairoskoh Sep 29, 2021
bc60895
Add Level 6
kairoskoh Sep 29, 2021
b2b063c
Add Level 7
kairoskoh Sep 29, 2021
253abe3
Merge pull request #3 from kairoskoh/branch-Level-5
kairoskoh Sep 29, 2021
4780c7e
Merge pull request #4 from kairoskoh/branch-Level-6
kairoskoh Sep 29, 2021
411c77a
Merge pull request #5 from kairoskoh/branch-Level-7
kairoskoh Sep 29, 2021
493ebcc
Add user guide
kairoskoh Sep 29, 2021
7db017f
Add more JavaDoc
kairoskoh Sep 29, 2021
2ac4093
Fix minor bug when saving tasks
kairoskoh Sep 29, 2021
0da697a
Remove hard-coded file paths
kairoskoh Sep 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Deadline extends Task{

protected final static char LETTER = 'D';
protected String date;

public Deadline(String description, String date) {
super(description);
this.date = date;
}

public String toString() {
return description;
}

public char getLetter() {
return LETTER;
}

public String getDate() {
return "(by: " + date + ")";
}

}
171 changes: 171 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,181 @@

import java.util.Scanner;

public class Duke {

public static void main(String[] args) {

// Welcome Message
PrintWelcomeMessage();

// Active Chat
ActiveChat();

// Goodbye Message
PrintGoodbyeMessage();
}

private static void ActiveChat() {

Choose a reason for hiding this comment

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

I think 'ActiveChat' should be 'activeChat' instead, since methods should be in camelCase.

boolean isBye = false;
boolean isEmptyList = true;
String input;
Scanner in = new Scanner(System.in);
int counter = 0;
Task[] list = new Task[100];

Choose a reason for hiding this comment

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

Perhaps 'tasks' is a more appropriate name, since it is plural.


while(!isBye){
//store input
input = in.nextLine();
//check if input is empty
CheckIsEmptyList(list);
//process input
if (input.equals("bye")){ //check if bye
isBye = true;
} else if (input.equals("list")) { //check if list
ProcessList(counter, list);
} else if (input.contains("done") ) { //check if done
ProcessDone(input, list);
} else {
counter = ProcessTasks(input, counter, list); //process tasks
}
}
}

private static void CheckIsEmptyList(Task[] list) {

Choose a reason for hiding this comment

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

'checkIsEmptyList' for 'CheckIsEmptyList', or perhaps even just 'isEmptyList' for boolean naming.
Similar camelCase method naming issues in other places as well.

boolean isEmptyList;
if(list[0] != null) {
isEmptyList = false;
}
}

private static void ProcessList(int counter, Task[] list) {
if (list[0] != null){
PrintListMessage(counter, list);
} else {
PrintListButEmptyMessage();
}
}

private static void ProcessDone(String input, Task[] list) {
int donePos = input.indexOf("done");
if (list[0] != null) {
if (input.length() < donePos + 5) {
PrintDoneButNotSpecificMessage(); //when input contains done but no number
} else {
ProcessDone(input, list, donePos); //when input contains done and specified number
}
} else {
PrintDoneButEmptyMessage(); //when input contains done but list is empty
}
}

private static void ProcessDone(String input, Task[] list, int donePos) {
String itemNumDone = input.substring(donePos + 5, donePos + 6);
int itemNum = Integer.parseInt(itemNumDone);
list[itemNum - 1].setDone();
PrintDoneMessage(list, itemNum);
}

private static int ProcessTasks(String input, int counter, Task[] list) {
if (input.contains("todo")) {

Choose a reason for hiding this comment

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

It might be cleaner to replace the strings "todo", "deadline", etc. with named constants of type static final String

String description = input.substring(5);
ToDo newTask = new ToDo(description);
list[counter] = newTask;
counter += 1;
PrintAddedTaskMessage(newTask, counter);
} else if (input.contains("deadline")) {
int donePos = input.indexOf("/"); //finds pos of '/'
String description = input.substring(9,donePos);
String date = input.substring(donePos + 4);
Deadline newTask = new Deadline(description,date);
list[counter] = newTask;
counter += 1;
PrintAddedTaskMessage(newTask, counter);

Choose a reason for hiding this comment

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

It might be cleaner to refactor this into a separate method.
One way is to have additional methods in the Duke class that handles the different Task subclasses.
Another is to create a separate class TaskManager that stores the array of Tasks and has functions to add the different Task subclasses to keep the main Duke class clean. (I think this will be the best approach)
Another is to overload the subclass constructors to take in String[] or a similar data structure.

} else if (input.contains("event")) {
int donePos = input.indexOf("/"); //finds pos of '/'
String description = input.substring(6,donePos);
String date = input.substring(donePos + 4);
Event newTask = new Event(description,date);
list[counter] = newTask;
counter += 1;
PrintAddedTaskMessage(newTask, counter);
} else {
System.out.println("Please specify tasks: todo, deadline or event");
System.out.println("Example - type in the following: todo read book");
}
return counter;
}

private static void PrintDoneMessage(Task[] list, int itemNum) {

Choose a reason for hiding this comment

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

Nice use of specific PrintMessage methods to keep the overall code cleaner and easier to understand

System.out.println("--------------------");
System.out.println("Nice! I've marked this task as done:");
System.out.println( itemNum + ".[" + list[itemNum - 1].getStatusIcon() + "] " + list[itemNum - 1].getDescription() );

Choose a reason for hiding this comment

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

Linked to the comment on overriding the .toString() method in Task. By doing so, this part of code can be simplified to

System.out.println( itemNum + "." + list[itemNum - 1])

System.out.println("--------------------");
}

private static void PrintListMessage(int counter, Task[] list) {
System.out.println("--------------------");
System.out.println("Here are the tasks in your list:");
for(int i = 0; i < counter; i += 1){
PrintListOfTaskSubMessage(list[i], i);
}
System.out.println("--------------------");
}

private static void PrintListButEmptyMessage() {
System.out.println("--------------------");
System.out.println("List is empty. Time to get productive!");
System.out.println("--------------------");
}

private static void PrintDoneButNotSpecificMessage() {
System.out.println("Please specify which task is done.");
}

private static void PrintDoneButEmptyMessage() {
System.out.println("--------------------");
System.out.println("Unable to tick off list.");
System.out.println("List is empty. Time to get productive!");
System.out.println("--------------------");
}

private static void PrintAddedTaskMessage(Task task, int i) {
System.out.println("--------------------");
System.out.println("Got it. I've added this task: ");
System.out.println("[" + task.getLetter() + "] "
+ "[" + task.getStatusIcon() + "] "

Choose a reason for hiding this comment

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

nice use of wrapped lines!

+ task.getDescription()
+ task.getDate() );
System.out.println("Now you have " + i + " tasks in the list.");
System.out.println("--------------------");
}

private static void PrintListOfTaskSubMessage(Task task, int i) {
System.out.println(i + 1
+ ".[" + task.getLetter() + "] "
+ "[" + task.getStatusIcon() + "] "
+ task.getDescription() );
}

private static void PrintGoodbyeMessage() {
System.out.println("--------------------");
System.out.println("Bye. Hope to see you again soon!");
System.out.println("");
System.out.println("--------------------");
}

private static void PrintWelcomeMessage() {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

System.out.println("--------------------");
System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you?");
System.out.println("");
System.out.println("--------------------");
}
}
24 changes: 24 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Event extends Task{

protected final static char LETTER = 'E';
protected String date;

public Event(String description, String date) {
super(description);
this.date = date;
}

public String toString() {
return description;
}

public char getLetter() {
return LETTER;
}

public String getDate() {
return "(at: " + date + ")";
}


}
37 changes: 37 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public class Task {
protected String description;
protected boolean isDone;

public Task(){
this.description = "";
isDone = false;
}
public Task(String description) {
this.description = description;
this.isDone = false;
}

Choose a reason for hiding this comment

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

Perhaps it will be cleaner to override the .toString() method to return the entire [T][ ] task name string, instead of needing separate public getLetter() and getStatusIcon() methods.

public String toString() {
    String checkbox = isCompleted ? "[X]" : "[ ]";
    return checkbox + " " + taskName;
}

It is also possible to further override the function in the subclasses.
Example for Deadline subclass

@Override
public String toString() {
    String checkbox = isCompleted ? "[X]" : "[ ]";
    return "[D]" + super.toString() + " " + "(by: " + by + ")";
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public String getDescription(){
return this.description;
}

public void setDone(){
this.isDone = true;
}

public void setDescription(String description) {
this.description = description;
}

public char getLetter() {
return ' ';
}

public String getDate() {
return " ";
}
}
21 changes: 21 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class ToDo extends Task{

protected final static char LETTER = 'T';

public ToDo(String description) {
super(description);
}

public String toString() {
return description;
}

public char getLetter() {
return LETTER;
}

public String getDate() {
return "";
}

}