Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Deadline extends Task {
public Deadline(String description, String deadline) {
super(description);
this.deadline=deadline;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(" + this.deadline + ")";
}
}
128 changes: 120 additions & 8 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,122 @@
import java.util.Scanner;


public class Duke {
public static int listCount = 0;
public static Task[] list = new Task[100];


public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
}
}
//Generates a greeting
greet();
request();
}

public static void bidGoodbye(){
System.out.println("Bye. Hope to see you again soon!");
}

public static void printList(){
int i;
for (i = 0; i < listCount; i++) {
System.out.println(listCount + "." + list[i]);
}
}

public static void markDone(String word){
int num = Integer.parseInt(word);
list[num - 1].isDone = true;
System.out.println("Nice! I've marked this task as done:");
System.out.println("[✓] " + list[num - 1].description);
System.out.println("Now you have " + listCount + " tasks in the list");
}

public static void todo(String line){
try {
list[listCount] = new ToDo(line);
System.out.println("Got it. I've added this task:");
System.out.println(list[listCount]);
System.out.println("Now you have " + listCount + " tasks in the list");
listCount++;
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("____________________________________________________________\n" +
"0x00002639 OOPS!!! The description of a todo cannot be empty.");
System.out.println("____________________________________________________________\n");
}
}

public static void Event(String line){
try{
int index = line.indexOf('/');
list[listCount] = new Event(line.substring(0, index - 1), line.substring(index + 1));
System.out.println("Got it. I've added this task:");
System.out.println(list[listCount]);
System.out.println("Now you have " + listCount + " tasks in the list");
listCount++;
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("____________________________________________________________\n" +
"☹ OOPS!!! The description of an event cannot be empty.");
System.out.println("____________________________________________________________\n");
}
}

public static void Deadline(String line){
try {
int index = line.indexOf('/');
list[listCount] = new Deadline(line.substring(0, index - 1), line.substring(index + 1));
System.out.println("Got it. I've added this task:");
System.out.println(list[listCount]);
System.out.println("Now you checkBoundsBeginEnd(have " + listCount + " tasks in the list");
listCount++;
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("____________________________________________________________\n" +
"☹ OOPS!!! The description of a deadline cannot be empty.");
System.out.println("____________________________________________________________\n");
}
}


public static void greet(){
System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you?");
}

public static void request() {
Scanner in = new Scanner(System.in);
String line;
while (true) {
line = in.nextLine();
String [] words = line.split(" ");
switch (words[0]) {
case "bye":
bidGoodbye();
break;
case "list":
printList();
break;
case "done":
markDone(line.substring(5));
break;
case "todo":
todo(line.substring(5));
break;
case "event":
Event(line.substring(6));
break;
case "deadline":
Deadline(line.substring(9));
break;
//case "delete":

default:
System.out.println("Command not supported");
break;
}
}
}





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

@Override
public String toString() {
return "[E]" + super.toString()+ "(" + this.deadline + ")";
}
}
23 changes: 23 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Task {
protected String description;
protected boolean isDone;
protected String deadline;
protected int listCount;


public Task(String description) {
this.description = description;
this.isDone = false;
this.listCount = 0;
this.deadline = " none";
}
public String statusicon(){
return (this.isDone?"[✓]":"[✗]");
}
@Override
public String toString(){
return statusicon() + description;
}


}
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 toString() {
return "[T]" + super.toString();
}
}