Skip to content
Open
Changes from 2 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1d65904
no message
rohitcube Sep 7, 2023
102f25f
commmit
rohitcube Sep 7, 2023
31650d6
seperated classes into seperate files
rohitcube Sep 8, 2023
3b2adcc
final with comments
rohitcube Sep 8, 2023
76a133a
actual final with comments
rohitcube Sep 8, 2023
fb4c7e8
switch statement and use of split method
rohitcube Sep 14, 2023
046aa40
exceptions and error handling
rohitcube Sep 15, 2023
6d3621e
put tasks into one package
rohitcube Sep 15, 2023
7d71e38
delete function
rohitcube Sep 21, 2023
47c89fa
2 functions added for saving tasks to file and transferring tasks fro…
rohitcube Oct 5, 2023
2ca1a03
JAR file tested
rohitcube Oct 5, 2023
2840b04
Level-7
rohitcube Oct 5, 2023
d9e74d0
Level-7
rohitcube Oct 5, 2023
22e6d32
Merge branch 'branch-Level-6'
rohitcube Oct 5, 2023
a185c4a
resolve merging issues with branch-Level-6
rohitcube Oct 5, 2023
d46612a
keyword search function
rohitcube Oct 5, 2023
a4fd5f6
Ui class
rohitcube Oct 5, 2023
afbf41f
OOP v1
rohitcube Oct 5, 2023
841f65c
OOP v2 with parser
rohitcube Oct 5, 2023
3731fe1
JavaDoc Update
rohitcube Oct 5, 2023
1552e4d
JavaDoc Update 2
rohitcube Oct 5, 2023
f26d5a3
JavaDoc Update 3
rohitcube Oct 5, 2023
4129c36
JavaDoc Update 4
rohitcube Oct 5, 2023
7a801e3
Merge pull request #2 from rohitcube/branch-Level-9
rohitcube Oct 5, 2023
c36c6f3
resolving merge conflicts
rohitcube Oct 5, 2023
afbb48e
resolving merge conflicts
rohitcube Oct 5, 2023
e9f3fd3
Merge pull request #1 from rohitcube/branch-A-JavaDoc
rohitcube Oct 5, 2023
cdec293
User Guide
rohitcube Oct 5, 2023
d71f127
removing comments
rohitcube Oct 5, 2023
7a861a7
delete line function
rohitcube Oct 6, 2023
a049895
fixed addtodo bug
rohitcube Oct 6, 2023
35b3563
added javadocs
rohitcube Oct 6, 2023
9cbbef5
Fix Empty Input Bugs
rohitcube Oct 21, 2023
372929a
Remove command class
rohitcube Oct 25, 2023
455325c
Add error messages for todo, event, deadline, unrecognized command
rohitcube Oct 25, 2023
6924d30
Add conditions to catch empty inputs for mark, unmark and find commands
rohitcube Oct 25, 2023
d615630
Fix bugs in 'deleteLineFromFile' function
rohitcube Oct 25, 2023
2254701
Add Error Messages to DukeyErrorMessages
rohitcube Oct 25, 2023
63815fe
Add JavaDoc to DukeyErrorMessages
rohitcube Oct 25, 2023
a25d92c
Add details to README
rohitcube Oct 25, 2023
b41095c
Add details to README
rohitcube Oct 25, 2023
25bd15c
Add details to README
rohitcube Oct 25, 2023
98e22e3
Add details to README
rohitcube Oct 25, 2023
6484d32
Add details to README
rohitcube Oct 25, 2023
d81536c
Add details to README
rohitcube Oct 25, 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
157 changes: 157 additions & 0 deletions src/main/java/Dukey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Dukey {
public static void main(String[] args) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Avoid long methods - could consider having different methods outside of the main method

ArrayList<Task> tasks = new ArrayList<>();
Scanner scanner = new Scanner(System.in);

String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
String line = "------------------------";

System.out.println(logo);
System.out.println("User");
System.out.println("ToDos: tasks without any date/time attached to it e.g., visit new theme park");
System.out.println("Deadlines: tasks that need to be done before a specific date/time e.g., submit report by 11/10/2019 5pm");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider splitting this line into shorter chunks.

System.out.println("Events: tasks that start at a specific date/time and ends at a specific date/time");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider incorporating these lines with the logo to avoid repeating "System.out.println".



System.out.println(line);

while (true) {
String userInput = scanner.nextLine();

if (userInput.equals("bye")) {
System.out.println(line);
System.out.println("Bye. Hope to see you again soon!");
break;
} else if (userInput.equals("list")) {
System.out.println(line);
if (tasks.isEmpty()) {
System.out.println("No tasks in the list.");
} else {
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + "." + tasks.get(i));
}
}
} else if (userInput.startsWith("deadline ")) {
String[] parts = userInput.split("/by");
String description = parts[0].substring(9).trim();
String by = parts[1].trim();
tasks.add(new Deadline(description, by));
System.out.println(line);
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " 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.

Consider adding whitespaces to improve readability.

} else if (userInput.startsWith("event ")) {
String[] parts = userInput.split("/from | /to ");
String description = parts[0].substring(6).trim();
String from = parts[1].trim();
String to = parts[2].trim();
tasks.add(new Event(description, from, to));
System.out.println(line);
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else if (userInput.startsWith("mark ")) {
int taskIndex = Integer.parseInt(userInput.split(" ")[1]) - 1;
if (taskIndex >= 0 && taskIndex < tasks.size()) {
tasks.get(taskIndex).markAsDone();
System.out.println(line);
System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + tasks.get(taskIndex));
} else {
System.out.println(line);
System.out.println("Invalid task index.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try to avoid arrowhead style convention. Perhaps you could have the marking and unmarking of task as a separate method.

}
} else if (userInput.startsWith("unmark ")) {
int taskIndex = Integer.parseInt(userInput.split(" ")[1]) - 1;
if (taskIndex >= 0 && taskIndex < tasks.size()) {
tasks.get(taskIndex).markAsNotDone();
System.out.println(line);
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(" " + tasks.get(taskIndex));
} else {
System.out.println(line);
System.out.println("Invalid task index.");
}
} else {
tasks.add(new Todo(userInput));
System.out.println(line);
System.out.println("added: " + userInput);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any reason why you chose nested loops?

System.out.println(line);
}
}
}

class Task {

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 should probably store the different classes in different files

protected String description;
protected boolean isDone;

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

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

public void markAsNotDone() {
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]");
}

@Override
public String toString() {
return getStatusIcon() + " " + description;
}
}

class Todo extends Task {
public Todo(String description) {
super(description);
}
}

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 + ")";
}
}

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;
}
}