Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class Main {
}
123 changes: 123 additions & 0 deletions src/main/java/Dukey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@


import Tasks.*;
import dukey.*;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Imported classes should always be listed explicitly.


import java.util.ArrayList;
import java.util.Scanner;

public class Dukey {
private static void addTodo(String line, ArrayList<Task> tasks) {
String[] words = line.split(" ");
String description = null;
try {
description = words[1];
tasks.add(new Todo(description));
tasks.get(tasks.size() - 1).printNewTask();
} catch(IndexOutOfBoundsException e) {
System.out.println("_____________________________________________________");

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 abstracting this out into a constant variable called LINE_DIVIDER.

System.out.println(DukeyException.todoDescriptionError());
System.out.println("_____________________________________________________");
}
}

private static void addEvent(String line, ArrayList<Task> tasks) {
int startIndexOfFrom = line.indexOf("/from");
int startIndexOfTo = line.indexOf("/to");
final int beginIndex = 6;
try {
String from = line.substring(startIndexOfFrom + 6, startIndexOfTo);
String to = line.substring(startIndexOfTo + 4);
String description = line.substring(beginIndex, startIndexOfFrom);
tasks.add(new Event(from, to, description));
tasks.get(tasks.size() - 1).printNewTask();
} catch(StringIndexOutOfBoundsException e) {
System.out.println("_____________________________________________________");
System.out.println(DukeyException.EventFormatError());
System.out.println("_____________________________________________________");
}
}

private static void addDeadline(String line, ArrayList<Task> tasks) {
String[] words = line.split("/by");
String[] words2 = line.split(" ");
try {
String description = words2[1];
String by = words[1];
tasks.add(new Deadline(description, by));
tasks.get(tasks.size() - 1).printNewTask();
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("_____________________________________________________");
System.out.println(DukeyException.deadlineDescriptionError());
System.out.println("_____________________________________________________");
}
}

private static void unmarkTask(String line, ArrayList<Task> tasks) {
String[] words = line.split(" ");
int taskNum = Integer.parseInt(words[1]) - 1;
tasks.get(taskNum).unmarkTask();
}

private static void markTask(String line, ArrayList<Task> tasks) {
String[] words = line.split(" ");
int taskNum = Integer.parseInt(words[1]) - 1;
tasks.get(taskNum).setDone();
}


public static void printTaskList(ArrayList<Task> tasks) {
System.out.println("Here are the tasks in your list:");
int index = 1;
for (Task task : tasks) {
System.out.println((index++) + "." + task);
}
}

public static void main(String[] args) {
System.out.println("Hey! I'm Dukey, your virtual assistant!\nWhat can I do for you?\n");
Scanner in = new Scanner(System.in);
String line;

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 changing the variable name to something more appropriate such as userInput.

ArrayList<Task> tasks = new ArrayList<>();

while (true) {
line = in.nextLine();
String[] words = line.split(" ");
String firstWord = words[0];
switch (firstWord) {
case "bye":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Take note of the coding standard violation here, the case clause should not have an indentation. You can change your IDE to follow the coding standard.

System.out.println("Bye. Hope to see you again soon!\n");
return;
case "list":
printTaskList(tasks);
break;
case "mark":
markTask(line, tasks);
break;
case "unmark":
unmarkTask(line, tasks);
break;
case "deadline":
addDeadline(line, tasks);
break;
case "event":
addEvent(line, tasks);
break;
case "todo":
addTodo(line, tasks);
break;
default:
if (line.trim().isEmpty()) {
System.out.println("________________________________");
System.out.println(DukeyException.EmptyInputError());
System.out.println("________________________________");
} else {
System.out.println("____________________________________________________________");
System.out.println(DukeyException.InvalidInputError());
System.out.println("____________________________________________________________");
}

}
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/Tasks/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Tasks;

import Tasks.Task;

public class Deadline extends Task {
private String due;

public Deadline(String description, String due) {
super(description);
this.due = due;
this.type = 'D';
}
// appends "[D]" to the beginning of the string.
// Then, it calls super.toString(), ie. it calls the toString() method of the superclass
// then adds the due date
@Override
public String toString() {
return "[" + this.type + "]" + super.toString() + " (by:"+ this.due + ")";
}
}
23 changes: 23 additions & 0 deletions src/main/java/Tasks/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Tasks;

import Tasks.Task;

public class Event extends Task {
private String from;
private String by;

public Event(String from, String by, String description) {
// call by the superclass (task) constructor
super(description);
this.from = from;
this.by = by;
this.type = 'E';
}
// appends "[R]" to the beginning of the string.
// Then, it calls super.toString(), ie. it calls the toString() method of the superclass
// then adds the from and to timings
@Override
public String toString() {
return "[E]" + super.toString() + "(from: " + this.from + "to: " + this.by + ")";
}
}
59 changes: 59 additions & 0 deletions src/main/java/Tasks/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package Tasks;

public class Task {
protected String description;
protected boolean isDone;

protected char type;
protected static int numTasks = 0;

public String getStatusIcon() {
return (isDone ? "X" : " ");
}
public static int getNumTasks() {
return numTasks;
}

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

public boolean isDone() {
return this.isDone;
}

public void setDone() {
this.isDone = true;
System.out.println("Nice! I've marked this task as done:\n\t " + this);
}
// defines constructor for the task class
public Task(String description) {
this.description = description;
this.isDone = false;
this.type = 'T';
numTasks++;
}

// made changes as an earlier comment mentioned it was better to have
// mark and unmark as two different functions
public void unmarkTask() {
this.isDone = false;
System.out.println("Nice! I've marked this task as done:\n\t " + this);
}

// the superclass toString outputs the mark box and the description
@Override
public String toString() {
return "[" + this.getStatusIcon() + "] " + this.getDescription();
}

//
public void printNewTask() {
System.out.print("Got it. I've added this task:\n " + this + "\nNow you have " + getNumTasks());
if (getNumTasks() > 1) {
System.out.println(" tasks in the list.");
} else {
System.out.println(" task in the list.");
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/Tasks/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Tasks;

import Tasks.Task;

public class Todo extends Task {
public Todo(String description) {
super(description);
}
// It appends "[T]" to the beginning of the string.
// Then, it calls super.toString(), which means it calls the toString() method of the superclass
@Override
public String toString() {
return "[T]" + super.toString();
}
}
28 changes: 28 additions & 0 deletions src/main/java/dukey/DukeyException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dukey;

public class DukeyException extends Exception {
public DukeyException(String message){
super(message);
}

public static String InvalidInputError(){
return "☹ OOPS!!! I'm sorry, but I don't know what that means :-(";
}

public static String EmptyInputError(){
return "☹ OOPS!!! I'm sorry, but you have to input something :-|";
}

public static String todoDescriptionError(){
return "☹ OOPS!!! The description of a todo cannot be empty.";
}

public static String deadlineDescriptionError(){
return "☹ OOPS!!! Please enter the description then '/by', followed by the time.";
}

public static String EventFormatError(){
return "☹ OOPS!!! Please enter '/from' and '/to' into your instructions.";
}

}