Skip to content

Commit

Permalink
Add task type
Browse files Browse the repository at this point in the history
Tasks do not have a type, making it hard to tell what is the nature of the task

Add types to differentiate between different types of task
  • Loading branch information
rgonslayer committed Aug 24, 2022
1 parent 6164900 commit bca45e9
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Deadline extends Task{
protected String by;

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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
42 changes: 32 additions & 10 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ public static void main(String[] args) {
System.out.println(introduction);

while (true) {
//receive user input
nextTask = inputScanner.nextLine();

//check if userinput is bye, break if true
if (nextTask.equals("bye")) {
break;
}

//if userinput equals list, return task list
if (nextTask.equals("list")) {
System.out.println("Here are the tasks in your list:\n");
for (int i = 0; i < taskList.length; i ++) {
if (taskList[i] == null) {
break;
Expand All @@ -29,27 +31,47 @@ public static void main(String[] args) {
}
continue;
}

if (nextTask.length() > 4 && nextTask.substring(0,4).equals("mark")) {
//if userinput equals mark, check which task and mark it
if (nextTask.length() > 4 && nextTask.substring(0, 4).equals("mark")) {
int toMark = Integer.parseInt(nextTask.substring(5)) - 1;
taskList[toMark].mark();
String markResponse = "Nice! I've marked this task as done:\n ";
System.out.println(markResponse + taskList[toMark].toString());
continue;
}

if (nextTask.length() > 6 && nextTask.substring(0,6).equals("unmark")) {
//if userinput equals unmark, check which task and unmark
if (nextTask.length() > 6 && nextTask.substring(0, 6).equals("unmark")) {
int toMark = Integer.parseInt(nextTask.substring(7)) - 1;
taskList[toMark].unmark();
String markResponse = "Ok, I've marked this task as not done yet:\n ";
System.out.println(markResponse + taskList[toMark].toString());
continue;
}
//if userinput equals to do add new to do task to list
if (nextTask.length() > 4 && nextTask.substring(0, 4).equals("todo")) {
taskList[Task.count] = new ToDo(nextTask);
System.out.println("Got it. I've added this task:\n " + taskList[Task.count - 1]
+ "\nNow you have " + (Task.count) + " tasks in the list.");
}

taskList[Task.count] = new Task(nextTask);

System.out.println("added: " + nextTask);

//if userinput equals deadline add new deadline task to list
if (nextTask.length() > 8 && nextTask.substring(0, 8).equals("deadline")) {
int divisor = nextTask.indexOf("/by");
String description = nextTask.substring(9, divisor - 1);
String date = nextTask.substring(divisor + 4);
taskList[Task.count] = new Deadline(description, date);
System.out.println("Got it. I've added this task:\n " + taskList[Task.count - 1]
+ "\nNow you have " + (Task.count) + " tasks in the list.");
}
//if userinput equals event add new event task to list
if (nextTask.length() > 7 && nextTask.substring(0,5).equals("event")) {
int divisor = nextTask.indexOf("/at");
String description = nextTask.substring(6, divisor - 1);
String date = nextTask.substring(divisor + 4);
taskList[Task.count] = new Event(description, date);
System.out.println("Got it. I've added this task:\n " + taskList[Task.count - 1]
+ "\nNow you have " + (Task.count) + " tasks in the list.");
}
}

System.out.println(farewell);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends Task{

protected String at;

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

@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + at + ")";
}
}
1 change: 1 addition & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public Task(String description) {
this.description = description;
this.isDone = false;
count++;

}

public void mark(){
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class ToDo extends Task{

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

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

0 comments on commit bca45e9

Please sign in to comment.