Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ab76983
Level-0 Increment, Greet and Exit message
SpeciLiam Jan 27, 2023
66f05b6
Level 1. Greet, Echo, Exit
SpeciLiam Jan 27, 2023
326cf60
Level 2. Add, List
SpeciLiam Jan 27, 2023
e77c524
LevevlLevel 3. Mark as Done
SpeciLiam Jan 31, 2023
2cc0131
A-CodingStandard
SpeciLiam Jan 31, 2023
489244b
Level 4. ToDos, Events, Deadlines
SpeciLiam Feb 2, 2023
9cc6ba3
A-CodeQuality
SpeciLiam Feb 2, 2023
9939b56
added class DukeException.java and switched from if statement structu…
SpeciLiam Feb 8, 2023
c8898cc
Added exception handling for todo and unknown command
SpeciLiam Feb 9, 2023
c233d69
A-Packages
SpeciLiam Feb 9, 2023
a760d20
Level 6. Delete
SpeciLiam Feb 15, 2023
238fb85
adding File Paths_1
SpeciLiam Feb 15, 2023
acd898a
Level 7. Save
SpeciLiam Feb 15, 2023
6940bc1
Merge branch 'branch-Level-6' into branch-Level-7
SpeciLiam Feb 15, 2023
96b58be
Changes for code readibility
SpeciLiam Feb 15, 2023
804bf2e
Merge Conflicts with branch 6 and 7
SpeciLiam Feb 15, 2023
d9dc7c1
Code Cleanup
SpeciLiam Feb 15, 2023
99237ca
A-MoreOOP
SpeciLiam Mar 2, 2023
f9bb7fe
Code Cleanup
SpeciLiam Mar 3, 2023
73543ab
Level 9. Find and code clean up
SpeciLiam Mar 3, 2023
cef26a2
Code Cleanup
SpeciLiam Mar 3, 2023
5886c71
A-JavaDoc
SpeciLiam Mar 3, 2023
c12849d
A-UserGuide
SpeciLiam Mar 3, 2023
eee98c8
Code clean-up and error handling better
SpeciLiam Mar 3, 2023
1b6cb39
Coding Standard Upkeep
SpeciLiam Mar 3, 2023
c222d8e
Commiting for jar related issues - made a change in code so that I ca…
SpeciLiam Mar 4, 2023
660cda3
Commiting for jar related issues - made a change in code so that I ca…
SpeciLiam Mar 4, 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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

179 changes: 179 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package duke;

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

import tasks.Task;
import tasks.Deadline;
import tasks.Event;
import tasks.Todo;

import dukeException.DukeException;
import dukeException.DukeIOBException;

public class Duke {

public Duke() {

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do consider removing empty methods, if not you could refactor some of your code into this. :)


/*
Main function that takes user input and interpets how to store and what to do with it
*/
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.

Do avoid leaving spaces like this as it goes against the Java Coding Standards

ArrayList<String> userInputs = new ArrayList<>();
ArrayList<Task> tasks = new ArrayList<>();
Scanner scan = new Scanner(System.in);
String logo = " ____ _ \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.

I notice that you have a tendency to use magic strings and numbers. Do try to avoid that where possible, and instead use constants to set your strings/numbers.


greetUser();

while (true) {
Task tsk = null;
String input = scan.nextLine();
String[] splitInput = input.split(" ");

switch (splitInput[0]) {
case "bye":
exit();
return;
case "todo":
try {
tsk = new Todo(splitInput[1], false);
addToList(input, userInputs);
tasks.add(tsk);
addTaskPrint(tasks, tsk);
} catch (IndexOutOfBoundsException de) {
printExceptionMsg("todo", "description of a todo cannot be empty.");
} catch (DukeException de) {

}


break;
case "event":
tsk = parseEvent(input);
addToList(input, userInputs);
tasks.add(tsk);
addTaskPrint(tasks, tsk);
break;
case "deadline":
tsk = parseDeadline(input);
addToList(input, userInputs);
tasks.add(tsk);
addTaskPrint(tasks, tsk);
break;
case "list":
listOut(userInputs, tasks);
break;
case "mark":
tasks.get(Integer.parseInt(splitInput[1]) - 1).mark();
System.out.println("\t____________________________________________________________");
System.out.println("\tNice! I've marked this task as done:");
System.out.println("\t " + tasks.get(Integer.parseInt(splitInput[1]) - 1));
System.out.println("\t____________________________________________________________");
break;
case "unmark":
tasks.get(Integer.parseInt(splitInput[1]) - 1).unMark();
System.out.println("\t____________________________________________________________");
System.out.println("\tOK, I've marked this task as not done yet:");
System.out.println("\t " + tasks.get(Integer.parseInt(splitInput[1]) - 1));
System.out.println("\t____________________________________________________________");
break;
default:
System.out.println("\t____________________________________________________________");
System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-(");;
System.out.println("\t____________________________________________________________");

break;
}
}
}
public static void printExceptionMsg(String task, String err) {
System.out.println("\t____________________________________________________________");
System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty.");
System.out.println("\t____________________________________________________________");
}
public static void addTaskPrint(ArrayList<Task> tasks, Task tsk) {
System.out.println("\t____________________________________________________________");
System.out.println("\tGot it. I've added this task:");
System.out.println("\t " + tsk.toString());
System.out.println("\tNow you have " + tasks.size() + " tasks in the list.");
System.out.println("\t____________________________________________________________");
}
/*
This Returns the input as a Deadline object

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please remove such comments as they go against the java coding standards.

*/
public static Deadline parseDeadline(String input) {
int idx = input.indexOf("/by");
String desc = input.substring(8, idx);
String by = input.substring(idx + 3);
Deadline tsk = null;
try {
tsk = new Deadline(desc, false, by);
} catch (DukeException de) {

}
return tsk;
}
/*
This Returns the input as a Event object
*/
public static Event parseEvent(String input) {
int idx = input.indexOf("/from");
int idx1 = input.indexOf("/to");
String desc = input.substring(5, idx);
String start = input.substring(idx + 5, idx1);
String end = input.substring(idx1 + 3, input.length());
Event tsk = null;
try {
tsk = new Event(desc, false, start, end);
} catch (DukeException de) {

}
return tsk;
}
/*
This Adds the input to an input array for the ability to keep track of
*/
public static void addToList(String cmd, ArrayList<String> userInputs) {
userInputs.add(cmd);
userInputs.set(userInputs.size() - 1, userInputs.size() + ". [ ] " + userInputs.get(userInputs.size() - 1));
}
/*
This method lists out the tasks in order
*/
public static void listOut(ArrayList<String> userInputs, ArrayList<Task> tasks) {
System.out.println("\t____________________________________________________________");
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < tasks.size(); i++) {
System.out.println("\t" + (i + 1) + "." + tasks.get(i));
}
System.out.println("\t____________________________________________________________");
}
/*
Automated greet function
*/
public static void greetUser() {
System.out.println("\t____________________________________________________________");
System.out.println("\tHello! I'm Duke");
System.out.println("\tWhat can I do for you?");
System.out.println("\t____________________________________________________________");
}
/*
Exit message
*/
public static void exit() {
System.out.println("\t____________________________________________________________");
System.out.println("\tBye. Hope to see you again soon!");
System.out.println("\t____________________________________________________________");

}

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

public class DukeException extends Throwable {

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 not to leave your exceptions empty. Perhaps you could have the corresponding error message and a method to print/return the error message?


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

public class DukeIOBException extends java.lang.ArrayIndexOutOfBoundsException {

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

import dukeException.DukeException;

public class Deadline extends Task {

protected String by;

public Deadline(String description, boolean isMark, String by) throws DukeException {
super(description, isMark);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by:" + by + ")";
}
}
21 changes: 21 additions & 0 deletions src/main/java/tasks/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tasks;

import dukeException.DukeException;

public class Event extends Task {

private String start;
private String end;


public Event(String description, boolean isMark, String start, String end) throws DukeException {
super(description, isMark);
this.start = start;
this.end = end;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(from:" + this.start + "to:" + this.end + ")";
}
}
32 changes: 32 additions & 0 deletions src/main/java/tasks/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tasks;

import dukeException.DukeException;

public class Task {
private String description;
private boolean isMark;
public Task(String inDescription, boolean isMark) throws DukeException {
if (inDescription.length() == 0) {
throw new DukeException();
}
this.description = inDescription;
this.isMark = isMark;
}
public void mark() {
this.isMark = true;
}
public void unMark() {
this.isMark = false;
}
public String getMarked() {
if (this.isMark) {
return "[X]";
} else {
return "[ ]";
}
}

public String toString() {
return this.getMarked() + " " + this.description;
}
}
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 dukeException.DukeException;

public class Todo extends Task {
public Todo(String description, boolean isMark) throws DukeException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please do remove the extra space between ) and throws!

super(description, isMark);

}

@Override
public String toString() {
return "[T]" + super.toString();
}
}