Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darren Tng IP #653

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
28 changes: 28 additions & 0 deletions src/main/java/Deadlines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Deadlines extends Task {

protected String deadlineby;

public Deadlines(String description) {
super(description);
}

public Deadlines(String description,String deadlineby) {
super(description);
this.deadlineby = deadlineby;
}

public String getDeadLine() {
return this.deadlineby;
}

public String getDeadLineTask() {
return description;
}

public String getItem() {
return "[D]";
}


}

250 changes: 243 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,246 @@
import jdk.jfr.Event;

import java.util.*;
import java.util.stream.Stream;
/*Week 2 done*/
/*Level 1*/
/*Need Fixing */.
public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
/*testing branch*/
private static final List<Task> ListofMessages = new ArrayList<>();

public static void Openingmessage() { /*Displays message when chatbot starts up*/
System.out.println("Hello! I'm Duke What can I do for you?");
}

public static void removeItem (int ItemIndex){
ListofMessages.remove(ItemIndex);
}

public static void DisplayListOfMessages() {
int LengthOfArrayList;
LengthOfArrayList = ListofMessages.size();
for (int i = 0; i < LengthOfArrayList; i++) {
int NumberToDisplay = i + 1;
if (ListofMessages.get(i) instanceof ToDos) {
String AdditemMessage = "[T]";
String finalmessage = NumberToDisplay + "." + AdditemMessage + "[" + ((ListofMessages.get(i)).getStatusIcon()) + "]" + ((ListofMessages.get(i)).getTask());
System.out.println(finalmessage);
}else if (ListofMessages.get(i) instanceof Deadlines) {
String ToManipulate = ListofMessages.get(i).getStatusIcon();
String ItemType = ((Deadlines) ListofMessages.get(i)).getItem();
String GetDateLine = ((Deadlines) ListofMessages.get(i)).getDeadLine();//Type casting
String TaskName = ((Deadlines) ListofMessages.get(i)).getDeadLineTask();
String finalmessage = NumberToDisplay + "." + ItemType + "[" + ListofMessages.get(i).getStatusIcon() + "] " + TaskName + "(by: " + GetDateLine + ")";
System.out.println(finalmessage);
}else if (ListofMessages.get(i) instanceof Events) {
String ToManipulate = ListofMessages.get(i).getStatusIcon();
String ItemType = ((Events) ListofMessages.get(i)).getItem();
String GetDateLine = ((Events) ListofMessages.get(i)).getEvent();
String TaskName = ((Events) ListofMessages.get(i)).getEventsDescription();
String finalmessage = NumberToDisplay + "." + ItemType + "[" + ListofMessages.get(i).getStatusIcon() + "] " + TaskName + "(at: " + GetDateLine + ")";
System.out.println(finalmessage);
} else {
String finalmessage = NumberToDisplay + ".[" + ((ListofMessages.get(i)).getStatusIcon()) + "]" + " " + ((ListofMessages.get(i)).getTask());
System.out.println(finalmessage);
}
}
}

public static String NumberOfItemsInList() {
int numberOfItems = ListofMessages.size();
String NumberOfItems = "Now you have " + numberOfItems + " tasks in the list.";
return NumberOfItems;
}

public static void main(String[] args) throws DukeException {

Openingmessage(); /*Opening Message*/
Scanner input = new Scanner(System.in);
int tasktobedone;

while (true) { //Main start

String message = input.next();

//Make sure message is valid
if(!(message.equals("list")) &&!(message.equals("todo"))&& !(message.equals("event"))&&
!(message.equals("deadline"))&&!(message.equals("delete"))){
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-();");
}

String ToDelete = "delete";
if (message.equals(ToDelete)) {
int nextvalue = input.nextInt() - 1;
Task tasktobehandled = ListofMessages.get(nextvalue);

if(tasktobehandled instanceof ToDos) {
String task = (((ToDos) tasktobehandled).getItem());
String item = ((tasktobehandled).getTask());
System.out.println("Noted. I've removed this task:");
String Tobedisplayed = " " + task + "[ ]" + item;
System.out.println(Tobedisplayed);
removeItem(nextvalue);
System.out.println(NumberOfItemsInList());
}else if(tasktobehandled instanceof Deadlines){
String deadline = (((Deadlines) tasktobehandled).getDeadLine());
String deadlinetask = (((Deadlines) tasktobehandled).getDeadLineTask());
String item = (((Deadlines) tasktobehandled).getItem());
System.out.println("Noted. I've removed this task:");
String Tobedisplayed = " " + item + "[ ]" + deadlinetask + " (by: "+ deadline + ")";
System.out.println(Tobedisplayed);
removeItem(nextvalue);
System.out.println(NumberOfItemsInList());
}else{ //instance of event
String eventdescription = (((Events) tasktobehandled).getEventsDescription()); //Task
String symbol = (((Events) tasktobehandled).getItem()); //Symbol
String item = (((Events) tasktobehandled).getEventsDescription()); //Due deate
System.out.println("Noted. I've removed this task:");
String Tobedisplayed = " " + symbol + "[ ]" + eventdescription + " (at: "+ item + ")";
System.out.println(Tobedisplayed);
removeItem(nextvalue);
System.out.println(NumberOfItemsInList());

}
//Remove at the end

}

String ToDoItem = "todo";
if (message.equals(ToDoItem)) {
String remainingmessage = input.nextLine();
ToDos t = new ToDos(remainingmessage);

//Fix this to try and catch blocks?
if (remainingmessage.isEmpty()) { //Message is only todo
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty.");
}

ListofMessages.add(t);
String GotIt = "Got it. I've added this task: ";
String DisplayItem = t.getItem();
String getStatus = t.getStatusIcon();
String DisplayItemWithTask = " " + DisplayItem + "[" + getStatus + "]" + remainingmessage;
System.out.println(GotIt);
System.out.println(DisplayItemWithTask);
System.out.println(NumberOfItemsInList());

}

//Deadline item
String DeadLineItem = "deadline";
if (message.equals(DeadLineItem)) {
try {
String remainingmessage = input.nextLine();

int i = 0;
int lengthofremainingmessage = remainingmessage.length();
//Locate the / icon
while (true) {
if (remainingmessage.charAt(i) == '/') {
break;
}
i = i + 1;
}
String firsthalf = remainingmessage.substring(1, i);
String secondhalf = remainingmessage.substring(i + 4, lengthofremainingmessage);
Deadlines t = new Deadlines(firsthalf, secondhalf);
ListofMessages.add(t);
String GotIt = "Got it. I've added this task: ";
System.out.println(GotIt);
//Display item with task
String DisplayItem = " " + t.getItem();
String getStatus = t.getStatusIcon();
getStatus = "[" + getStatus + "] ";
String DisplayItemWithTask = DisplayItem + getStatus + firsthalf + "(" + "by: " + secondhalf + ")";
System.out.println(DisplayItemWithTask);
System.out.println(NumberOfItemsInList());
} catch (StringIndexOutOfBoundsException e) {
throw new DukeException(" ☹ OOPS!!! The description of a deadline cannot be empty.");
}

}

//For events
String Eventitem = "event";
if (message.equals(Eventitem)) {
String remainingmessage = input.nextLine();
int i = 0;
int lengthofremainingmessage = remainingmessage.length();
//Locate the / icon
while (true) {
if (remainingmessage.charAt(i) == '/') {
break;
}
i = i + 1;
}

String firsthalf = remainingmessage.substring(1, i);
String secondhalf = remainingmessage.substring(i + 4, lengthofremainingmessage);

Events t = new Events(firsthalf, secondhalf);
ListofMessages.add(t);
String GotIt = "Got it. I've added this task: ";
System.out.println(GotIt);
//Display item with task
String DisplayItem = " " + t.getItem();
String getStatus = t.getStatusIcon();
getStatus = "[" + getStatus + "] ";
String DisplayItemWithTask = DisplayItem + getStatus + firsthalf + "(" + "at: " + secondhalf + ")";
System.out.println(DisplayItemWithTask);
System.out.println(NumberOfItemsInList());


}
//Command is list
String ToShowMessagesInArrayList = "list";
if (message.equals(ToShowMessagesInArrayList)) {
DisplayListOfMessages();
}

//Check if the message is done
String CheckIfTaskIsDone = "done";
if (message.equals(CheckIfTaskIsDone)) {
tasktobedone = (input.nextInt()) - 1;
Task TheTask = (ListofMessages.get(tasktobedone));


if (TheTask instanceof ToDos) {
TheTask.setStatus();
ListofMessages.set(tasktobedone, TheTask);
System.out.println("Nice! I've marked this task as done");
String ToBeprinted = TheTask.getStatusIcon();
ToBeprinted = "[" + ToBeprinted + "]" + TheTask.getTask();
System.out.println(ToBeprinted);
} else if (TheTask instanceof Deadlines) {
TheTask.setStatus();
ListofMessages.set(tasktobedone, TheTask);
System.out.println("Nice! I've marked this task as done");
String ToBeprinted = TheTask.getStatusIcon();
// String ToAdd = ((Deadlines) ListofMessages.get(tasktobedone)).getDeadLineTask();
ToBeprinted = "[" + ToBeprinted + "]" + TheTask.getTask();
System.out.println(ToBeprinted);
} else {
TheTask.setStatus();
ListofMessages.set(tasktobedone, TheTask);
System.out.println("Nice! I've marked this task as done");
String ToBeprinted = TheTask.getStatusIcon();
String ToAdd = ((Events) ListofMessages.get(tasktobedone)).getEventsDescription();
// System.out.println("hello world");
// System.out.println(ToAdd);
ToBeprinted = "[" + ToBeprinted + "]" + TheTask.getTask();
System.out.println(ToBeprinted);
}

}
//Command is Exit
String ToExit = "bye";
if (message.equals(ToExit)) {
System.out.println("Bye. Hope to see you again soon!");
break;
}

}//Main End

}
}
11 changes: 11 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class DukeException extends Exception{

public DukeException(String message) {
super(message);
}



}


28 changes: 28 additions & 0 deletions src/main/java/Events.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Events extends Task {

protected String Eventsdeadlineby;

public Events(String description) {
super(description);
}

public Events(String description,String Eventsdeadlineby) {
super(description);
this.Eventsdeadlineby = Eventsdeadlineby;
}

public String getEventsDescription() {
return description;
}

public String getEvent() {
return this.Eventsdeadlineby;
}

public String getItem() {
return "[E]";
}



}
28 changes: 28 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Task {
protected String description;
protected boolean isDone;
/*test*/
public Task(String description) {
this.description = description;
this.isDone = false;
}

public Task(String description,int x){
this.description = description;
this.isDone = true;
}

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

public void setStatus(){
isDone = true;
}


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

}
18 changes: 18 additions & 0 deletions src/main/java/ToDos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class ToDos extends Task {


public ToDos(String description) {
super(description);
}

public ToDos(String testTest, int x) {
super(testTest);
}


public static String getItem() {
return "[T]";
}


}