Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
de8ed4d
Achieved Level 0
geraldkoh4 Jan 24, 2023
5d5cc71
Minor Change in spelling
geraldkoh4 Jan 25, 2023
bc93fd2
Finished Level 1
geraldkoh4 Jan 25, 2023
7d21da9
Finished Level-2
geraldkoh4 Jan 25, 2023
6d10d3f
Finished Level-3
geraldkoh4 Jan 25, 2023
444b5c0
Finished level-4 and edited level 0, 1, 2 and 3
geraldkoh4 Jan 31, 2023
f7d165c
Minor format changes
geraldkoh4 Jan 31, 2023
25dffa2
Finished Level 5
geraldkoh4 Feb 7, 2023
609c4a9
Merge branch 'branch-Level-5'
geraldkoh4 Feb 12, 2023
544ba64
Minor changes to main, added DukeSession and fixed minor bugs
geraldkoh4 Feb 12, 2023
8902eae
Level-6 done, with some minor changes to arraylist and actioncounter …
geraldkoh4 Feb 12, 2023
69d4b63
Merge branch 'branch-Level-6'
geraldkoh4 Feb 12, 2023
959c5a4
Finished Level-7, fixed some bugs for Level-6 as well
geraldkoh4 Feb 12, 2023
13f7505
Merge branch 'branch-Level-7'
geraldkoh4 Feb 12, 2023
8a06c04
No idea what this does. Im trying to keep everything up to date.
geraldkoh4 Feb 12, 2023
e0c6dc9
Finished Level-9
geraldkoh4 Mar 1, 2023
391f7bf
Merge branch 'branch-Level-9'
geraldkoh4 Mar 1, 2023
77ef37e
Implemented JavaDoc and other Ui debugging and formatted strings.
geraldkoh4 Mar 2, 2023
6ba8f86
Merge pull request #1 from geraldkoh4/branch-A-JavaDoc
geraldkoh4 Mar 2, 2023
f423633
Update README.md
geraldkoh4 Mar 2, 2023
bf20902
Merge pull request #2 from geraldkoh4/A-UserGuide
geraldkoh4 Mar 2, 2023
cbc2097
Final and Minor formatting changes. Hope everything is working well!
geraldkoh4 Mar 3, 2023
c9f98f4
Update README.md
geraldkoh4 Mar 3, 2023
7831692
Minor Bug fixes
geraldkoh4 Mar 3, 2023
6df56ee
Update README.md
geraldkoh4 Mar 3, 2023
f4792f0
Update README.md
geraldkoh4 Mar 3, 2023
a7d571e
Update README.md
geraldkoh4 Mar 3, 2023
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
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 by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}
@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
72 changes: 66 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
import java.util.Scanner;
public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Methods.printGreetings();

Task[] actions = new Task[100];
int actionCounter = 0;

String line;
Scanner in = new Scanner(System.in);
int taskNumber;
String[] decisions;
Task toBeAdded;
String[] dates;
do {
line = in.nextLine();
decisions = line.split(" ");
dates = line.split("/");
switch (decisions[0]) {
case "echo":
System.out.println(Methods.findTaskDetails(line));
break;

case "todo":
toBeAdded = new Todo(Methods.findTaskDetails(line));
actions[actionCounter] = toBeAdded;
actionCounter++;
Methods.printAcknowledgement(toBeAdded,actionCounter);
break;

case "event":
toBeAdded = new Event(Methods.findTaskDetails(dates[0]), Methods.findTaskDetails(dates[1]), Methods.findTaskDetails(dates[2]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When wrapping texts, remember to indent 8 spaces (or 2 tabs) from former line

actions[actionCounter] = toBeAdded;
actionCounter++;
Methods.printAcknowledgement(toBeAdded,actionCounter);
break;

case "deadline":
toBeAdded = new Deadline(Methods.findTaskDetails(dates[0]), Methods.findTaskDetails(dates[1]));
actions[actionCounter] = toBeAdded;
actionCounter++;
Methods.printAcknowledgement(toBeAdded,actionCounter);
break;

case "mark":
taskNumber = Integer.parseInt(decisions[1]) - 1;
actions[taskNumber].mark();
Methods.printDoneMarkingTasks(actions[taskNumber]);
break;

case "unmark":
taskNumber = Integer.parseInt(decisions[1]) - 1;
actions[taskNumber].unmark();
Methods.printDoneMarkingTasks(actions[taskNumber]);
break;

case "list":
if (actionCounter == 0) {
Methods.printEmptyList();
continue;
}
for (int iterator = 0; iterator < actionCounter; iterator++) {
Methods.printListElement(iterator, actions[iterator]);
}
break;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps you could include a default branch for your switch block so in the case where your command is not caught by any of the case statements, your code will still function.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job on formatting your case statements!

} while (!decisions[0].equals("bye"));
System.out.println("That's all from me! Goodbye!");
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps you can consider how to abstract your main method into various different methods as currently it is rather lengthy (Greater than 30 LOC).

17 changes: 17 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Event extends Task {

protected String from;
protected String to;

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

@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + "to: " + to + ")";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remember to remove extra new lines in your code!

}
}
39 changes: 39 additions & 0 deletions src/main/java/Methods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.Scanner;
public class Methods {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use on plurals to define your class!

public static void printGreetings() {
String logo = " ____ _ \n"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You might want to consider declaring these variables as constants instead as they are they do not need to change.

+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n"
+ "__________________________\n";
System.out.println("Hello from\n" + logo);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job on wrapping the texts!

System.out.println("Hello! Do you need anything from me?\n"
+ "I have only been trained to greet, echo and list you so far.\n"
+ "Once my owner is more proficient in what he does, he will give me more functions!\n"
+ "Key in a number based on the function\n 1)echo \n 2)todo\n 3)mark\n 4)unmark\n 5)deadline\n 6)event\n"
+ "When you wish to exit, do tell me by typing : bye");
}
public static void print(String input) {
System.out.println(input);
}

public static void printEmptyList() {
System.out.println("There is nothing to list!");
}

public static void printListElement(int iterator, Task action) {
Methods.print(iterator + 1
+ ")"
+ action.toString());
}
public static void printDoneMarkingTasks(Task action) {
Methods.print("Done!\n" + action.toString());
}
public static String findTaskDetails(String line) {
return line.substring(line.indexOf(" ") + 1);
}
public static void printAcknowledgement(Task action, int actionCounter) {
System.out.println("Got it. I've added this task:\n" + action.toString() + System.lineSeparator() + "Now you have " + actionCounter + " tasks in the list.");
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you did a good job at making your method names simple yet descriptive. This makes it easy to follow the program flow.

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

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}
public void mark() {
this.isDone = true;
}
public void unmark() {
this.isDone = false;
}
public String getDescription() {
return(this.description);
}
public String toString() {
return( "[" + this.getStatusIcon() + "] " + this.getDescription());
}
}
12 changes: 12 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Todo extends Task {
public Todo(String description) {
super(description);
}
@Override
public String toString() {
return "[T]" + super.toString();
}

}