Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a63c9f7
Level-0
LimHongYao Jan 17, 2023
ef8d231
Added echo
LimHongYao Jan 27, 2023
bdd7c9d
Added list functionality
LimHongYao Jan 27, 2023
9d94709
Added ability to mark and unmark as done
LimHongYao Jan 31, 2023
a3a4347
Added deadline, event, todo types for list objects
LimHongYao Feb 9, 2023
c711aeb
fixed coding standard issues
LimHongYao Feb 9, 2023
28406be
added bad input handling
LimHongYao Feb 10, 2023
c2a4627
Merge branch 'branch-Level-5'
LimHongYao Feb 10, 2023
6cf1e94
added delete functionality to list
LimHongYao Feb 24, 2023
e3a2df5
added tasklist export functionality
LimHongYao Feb 26, 2023
e0bf091
reverted desktop export path to relative /out path
LimHongYao Feb 28, 2023
e3091cd
Merge branch 'branch-Level-6'
LimHongYao Feb 28, 2023
896ad76
Merge branch 'branch-Level-7'
LimHongYao Feb 28, 2023
44155f7
packaged files
LimHongYao Feb 28, 2023
95409e7
moved some methods to Ui class
LimHongYao Feb 28, 2023
fd05d8e
rewrote and combined mark/unmark methos
LimHongYao Mar 1, 2023
6e7bbe3
reworked and combined mark method
LimHongYao Mar 1, 2023
bc51fbb
Moved switch cases into OOP
LimHongYao Mar 2, 2023
81192bc
added search functionality
LimHongYao Mar 3, 2023
0021e8a
Merge pull request #1 from LimHongYao/branch-Level-9
LimHongYao Mar 3, 2023
4984f8c
added parser class
LimHongYao Mar 3, 2023
61ec054
Merge pull request #2 from LimHongYao/branch-Level-9
LimHongYao Mar 3, 2023
39fb97b
added load from text file functionality
LimHongYao Mar 3, 2023
30d3513
Added javadoc documentation
LimHongYao Mar 3, 2023
86c9546
added javadoc documentation
LimHongYao Mar 3, 2023
0200dab
Merge pull request #3 from LimHongYao/branch-A-JavaDoc
LimHongYao Mar 3, 2023
7ba7c8e
Updated basic user guide
LimHongYao Mar 3, 2023
ca442dc
Added UserGuide documentation in docs directory for website
LimHongYao Mar 16, 2023
3fff458
fixed bug with exception handling
LimHongYao Mar 16, 2023
488a811
re-commit with missing DukeException file
LimHongYao Mar 16, 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
22 changes: 22 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Deadline extends Task {
protected String dueDate;

public Deadline(String description, String dueDate) {
super(description);
this.dueDate = dueDate;
}
@Override
public String getTypeIcon() {
return "D";
}

public String getDueDate() {
return dueDate;
}

@Override
public String getTask() {
return taskTypeIcon() + isDoneIcon() + getDescription()
+ " (by: " + getDueDate() + ")";
}
}
145 changes: 139 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,143 @@
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class Duke {
static final int COMMAND_INDEX = 0;

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 using constants for your numbers! You could extend that to magic strings as well!

static final int MAX_COMMAND_LENGTH = 1;
static final int DESCRIPTION_INDEX = 1;
static final int STARTDATE_INDEX = 0;
static final int ENDDATE_INDEX = 1;

public static void exitMessage() {
System.out.println("Go away Anna");
System.out.println("O-kay bye......");
}

public static String getItemDescription(String userInput) {
Scanner in = new Scanner(System.in);
String description;
try {
description = userInput.split(" ", 2)[DESCRIPTION_INDEX];
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("What are you referring to?");
description = in.nextLine().trim();
}
return description;
}

public static String getDueDate(String userInput) {
Scanner in = new Scanner(System.in);
String dueDate;
if (userInput.contains("/by")) {
dueDate = userInput.substring(userInput.indexOf("/by"));
} else {
System.out.println("When is this due by?");
dueDate = in.nextLine().trim();
}
return dueDate;
}

public static String[] getStartEndDates(String userInput) {
Scanner in = new Scanner(System.in);
String[] StartEndDates = new String[2];

if (userInput.contains("/from")) {
StartEndDates[STARTDATE_INDEX] = userInput.substring(userInput.indexOf("/from"),userInput.indexOf("/to")).trim();
} else {
System.out.println("When does this event start?");
StartEndDates[STARTDATE_INDEX] = in.nextLine().trim();
}

if (userInput.contains("/to")) {
StartEndDates[ENDDATE_INDEX] = userInput.substring(userInput.indexOf("/to")).trim();
} else {
System.out.println("When does this event end?");
StartEndDates[ENDDATE_INDEX] = in.nextLine().trim();
}
return StartEndDates;
}
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("Hi it's Anna!\nWhat do you need to do?");
Scanner in = new Scanner(System.in);

while (true) {
String userInput = in.nextLine().trim();
ArrayList <String> input = new ArrayList<>();
input.add(COMMAND_INDEX, userInput.split(" ", 2)[COMMAND_INDEX]);
String inputCommand = input.get(COMMAND_INDEX);

switch (inputCommand) {
case "bye":
exitMessage();
return;
case "list":
if (TaskList.getNumItems() == 0) {
System.out.println("We are free! Let's go play!");
} else {
System.out.println("Here's what we've gotta do:");
TaskList.viewList();
}
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.

Do avoid leaving the space between each case as per the Java Coding Standards

case "mark": {
String itemNum = getItemDescription(userInput);

TaskList.markDone(Integer.parseInt(itemNum) - 1);
System.out.println("Okay I've marked item " + itemNum + " as done:");
TaskList.printItem(Integer.parseInt(itemNum) - 1);
break;
}

case "unmark": {
String itemNum = getItemDescription(userInput);

TaskList.markNotDone(Integer.parseInt(itemNum) - 1);
System.out.println("Oh no! Are we not done with " + itemNum + " after all?");
TaskList.printItem(Integer.parseInt(itemNum) - 1);
break;
}

case "add": {
String itemDescription = getItemDescription(userInput);
Task newTask = new Task(itemDescription);
TaskList.addItem(newTask);
break;
}

case "todo": {
String itemDescription = getItemDescription(userInput);
Todo newTask = new Todo(itemDescription);
TaskList.addItem(newTask);
break;
}

case "deadline": {
String itemDescription = getItemDescription(userInput);
String dueDate = getDueDate(userInput);
Deadline newTask = new Deadline(itemDescription,dueDate);
TaskList.addItem(newTask);
break;
}

case "event":
String itemDescription = getItemDescription(userInput);
String[] StartEndDates = getStartEndDates(userInput);
String startDate = StartEndDates[STARTDATE_INDEX];
String endDate = StartEndDates[ENDDATE_INDEX];
Event newTask = new Event(itemDescription,startDate,endDate);
TaskList.addItem(newTask);
break;

default:
System.out.println("I didn't get that!");
break;

}
}
}
}




27 changes: 27 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Event extends Task{
String startDate, endDate;
public Event(String description, String startDate, String endDate) {
super(description);
this.startDate = startDate;
this.endDate = endDate;
}
@Override
public String getTypeIcon() {
return "E";
}

public String getStartDate() {
return startDate;
}

public String getEndDate() {
return endDate;
}

@Override
public String getTask() {
return taskTypeIcon() + isDoneIcon() + getDescription() + System.lineSeparator()
+ "Start: " + getStartDate() + System.lineSeparator()
+ "End: " + getEndDate();
}
}
39 changes: 39 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

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

public Task(String description) { //ok to leave as public?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes you need to leave it as public. But do remove such comments from your code as it goes against the java coding standard. 👍

this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}
public String getTypeIcon() {
return "NULL";
}
public String taskTypeIcon() { return "[" + getTypeIcon() + "]";}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Even though these are simple 1 liners, please do still follow the proper style (aka Egyptian Style).

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

public void markDone() {
isDone = true;
}

public void markNotDone() {
isDone = false;
}

public String isDoneIcon() { return "[" + getStatusIcon() + "]";}
public String getDescription() {
return description;
}

public String getTask() {
return taskTypeIcon() + isDoneIcon() + " " + getDescription();
}

}
40 changes: 40 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.util.ArrayList;

public class TaskList {
private static final ArrayList<Task> TaskList = new ArrayList<>(10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ArrayList is a type of dynamic array and there is no need to limit your TaskList to a size of 10 only!

private static int NumTasks = 0;
public static void addItem (Task newTask) {
TaskList.add(newTask);
NumTasks += 1;
System.out.println("Okay! I've added: [" + newTask.getTypeIcon() +"] " + newTask.getDescription());
}
public static int getNumItems() {
return NumTasks;
}
public static void viewList () {
for (int i = 0; i < TaskList.size(); ++i) {
System.out.print(i+1 + ". ");

System.out.println(TaskList.get(i).getTask());
}
}
public static void markDone (int 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.

There should not be a space between markDone and (. Do change this for your other methods as well :)

if (TaskList.get(index).getStatusIcon().equals(" ")) {
TaskList.get(index).markDone();
}
}
public static void markNotDone (int index) {
if (TaskList.get(index).getStatusIcon().equals("X")) {
TaskList.get(index).markNotDone();
}
}
public static Task getItem (int index) {
return TaskList.get(index);
}
public static void printItem (int index) {
System.out.print(index+1 + ". ");
System.out.println(TaskList.get(index).getTask());
}


}
10 changes: 10 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Todo extends Task {
public Todo(String description) {
super(description);
}

@Override
public String getTypeIcon() {
return "T";
}
}