Skip to content
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

81 changes: 81 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String line;
ArrayList<Task> tasks = new ArrayList<>();
Scanner sc = new Scanner(System.in);
printHorizontalLine();
System.out.println(" Hello! I'm Duke");
System.out.println(" What can I do for you?");
printHorizontalLine();
line = sc.nextLine();
while (!line.equals("bye")) {
try {
if (line.equals("list")) {
printHorizontalLine();
System.out.println(" Here are the tasks in your list:");
for (int i = 0; i < tasks.size(); i++) {
System.out.println(" " + (i + 1) + ":" + tasks.get(i));
}
printHorizontalLine();
} else if (line.startsWith("done")) {
printHorizontalLine();
int taskNumberCompleted = Integer.parseInt(line.replaceAll("\\D+", "")) - 1;
tasks.get(taskNumberCompleted).completeTask();
System.out.println(" Nice! I've marked this task as done:");
System.out.println(" " + ":" + tasks.get(taskNumberCompleted));
printHorizontalLine();
System.out.println();
} else if (line.startsWith("todo")) {
printHorizontalLine();
System.out.println(" Got it. I've added this task:");
tasks.add(new ToDo(line));
System.out.println(" " + new ToDo(line));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
printHorizontalLine();
} else if (line.startsWith("deadline")) {
printHorizontalLine();
System.out.println(" Got it. I've added this task:");
tasks.add(new Deadline(line));
System.out.println(" " + new Deadline(line));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
printHorizontalLine();
} else if (line.startsWith("event")) {
printHorizontalLine();
System.out.println(" Got it. I've added this task:");
tasks.add(new Event(line));
System.out.println(" " + new Event(line));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
printHorizontalLine();
} else if (line.isEmpty()) {
printHorizontalLine();
System.out.println(" ☹ OOPS!!! The description of a task cannot be empty.");
printHorizontalLine();
} else {
printHorizontalLine();
System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
printHorizontalLine();
System.out.println();
}
} catch (StringIndexOutOfBoundsException e) {
printHorizontalLine();
System.out.println("The task you input has missing fields!");
printHorizontalLine();
} catch (Exception e) {
printHorizontalLine();
System.out.println("Something went wrong!");
printHorizontalLine();
}
line = sc.nextLine();
}
printHorizontalLine();
System.out.println(" Bye. Hope to see you again soon!");
printHorizontalLine();
}

private static void printHorizontalLine() {
System.out.println(" ____________________________________________________________");
}
}
23 changes: 23 additions & 0 deletions src/main/java/duke/tasks/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tasks;

public class Deadline extends Task{
protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}

public String getBy() {
return by;
}

public void setBy(String by) {
this.by = by;
}

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

public class Event extends Task{
protected String period;

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

public String getPeriod() {
return period;
}

public void setPeriod(String period) {
this.period = period;
}

@Override
public String toString() {
return "[E]" + super.toString() + String.format(" (at: %s)",this.getPeriod());
}
}
74 changes: 74 additions & 0 deletions src/main/java/duke/tasks/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package tasks;

import Commands;

import java.util.ArrayList;

public class Task {
protected String description;
protected boolean isDone;
protected static int numTotalTasks = 0;

protected Task(String description) {
this.description = description;
this.isDone = false;
numTotalTasks++;
}

public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols
}

public void setDone() {
isDone = true;
}

public String getDescription() {
return description;
}

public static int getNumTotalTasks() {
return numTotalTasks;
}

@Override
public String toString(){
return "[" + this.getStatusIcon() + "]" + this.getDescription();
}

public static boolean parseTask(String taskInString, ArrayList<Task> tasks) {
char type = taskInString.charAt(1);
char status = taskInString.charAt(4);
taskInString = taskInString.substring(6);
Task buffer;
String[] splitCommands;
String description;
String time;

switch (type) {
case 'T':
buffer = new Todo(taskInString);
break;
case 'E':
splitCommands = taskInString.split("\\(at: ");
description = splitCommands[0].strip();
time = splitCommands[1].substring(0, splitCommands[1].length()-1).strip();
buffer = new Event(description, time);
break;
case 'D':
splitCommands = taskInString.split("\\(by: ");
description = splitCommands[0].strip();
time = splitCommands[1].substring(0, splitCommands[1].length()-1).strip();
buffer = new Deadline(splitCommands[0], splitCommands[1]);
break;
default:
System.out.println("Error: Wrong input file syntax.");
return false;
}
if (status == '\u2713') {
buffer.setDone();
}
tasks.add(buffer);
return true;
}
}
12 changes: 12 additions & 0 deletions src/main/java/duke/tasks/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tasks;

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

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