Skip to content

Commit

Permalink
Level-4 Added Deadline, event, todo tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertybox123 committed Aug 29, 2023
1 parent ef089b7 commit ed92cb2
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 6 deletions.
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 Tasks {
private String deadline;

public Deadline(String name, boolean isMarked, String deadline) {
super(name, isMarked);
this.deadline = deadline;
}

public String getDeadline() {
return deadline;
}

public void setDeadline(String deadline) {
this.deadline = deadline;
}

@Override
public String toString() {
String status = isMarked ? "[X]" : "[ ]";
return "[D]" + status + " " + name + " (by: " + deadline + ")";
}
}
64 changes: 60 additions & 4 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ public static void main(String[] args) {
while (true) {
System.out.print("Enter a command: ");
String command = scanner.nextLine();
if (command.equalsIgnoreCase("bye")) {
if (command.equalsIgnoreCase("bye")) { // bye exits the code
Exit exit = new Exit();
System.out.println(exit.exitMessage());
break;
} else if (command.equalsIgnoreCase("list")) {
} else if (command.equalsIgnoreCase("list")) { //list shows the task list
System.out.println("Here are the tasks in your list: ");
if (!tasksList.isEmpty()) {
for (int i = 1; i <= tasksList.size(); i++) {
System.out.println(i + "." + tasksList.get(i - 1));
}
}
} else if (command.contains("unmark")) {
} else if (command.startsWith("unmark")) { // unmark the task in question
int taskNumber = Integer.parseInt(command.substring(7)) - 1;
if (taskNumber < tasksList.size()) {
Tasks task = tasksList.get(taskNumber);
task.setMarked(false);
tasksList.set(taskNumber, task);
System.out.println("OK, I've marked this task as not done yet:\n" + " " + tasksList.get(taskNumber));
}
} else if (command.contains("mark")) {
} else if (command.startsWith("mark")) { // mark the task in question
int taskNumber = Integer.parseInt(command.substring(5)) - 1;
if (taskNumber < tasksList.size()) {
Tasks task = tasksList.get(taskNumber);
Expand All @@ -39,6 +39,62 @@ public static void main(String[] args) {
}


} else if (command.startsWith("todo")) {
String description = command.substring(5);
Todo todo = new Todo(description, false);
System.out.println();
tasksList.add(todo);
System.out.println("Got it. I've added this task:");
System.out.println(" " + todo);
System.out.println("Now you have " + tasksList.size() + " tasks in the list");

} else if (command.startsWith("deadline")) {
// Split the input
String descriptionDeadline = command.substring(9).trim(); // Remove "deadline" and leading spaces

// Find the index of the deadline separator "/"
int separatorIndex = descriptionDeadline.indexOf('/');

if (separatorIndex != -1) { // Ensure the separator exists in the input
// Extract the task description and deadline
String description = descriptionDeadline.substring(0, separatorIndex).trim();
String deadline = descriptionDeadline.substring(separatorIndex + 4).trim();

// Create a new Deadline object
Deadline deadlineTask = new Deadline(description, false, deadline);
tasksList.add(deadlineTask);

System.out.println("Got it. I've added this deadline:");
System.out.println(" " + deadlineTask);
System.out.println("Now you have " + tasksList.size() + " tasks in the list");
} else {
System.out.println("Invalid input format for deadline command.");
}
} else if (command.startsWith("event")) {
// split the input
String descriptionStartEndTime = command.substring(6).trim(); // Remove "event" and leading spaces

// Find the indices of the time separators
int fromIndex = descriptionStartEndTime.indexOf("/from");
int toIndex = descriptionStartEndTime.indexOf("/to");

if (fromIndex != -1 && toIndex != -1) {
// Extract the task description, startTime, and endTime
String description = descriptionStartEndTime.substring(0, fromIndex).trim();
String startTime = descriptionStartEndTime.substring(fromIndex + 5, toIndex).trim();
String endTime = descriptionStartEndTime.substring(toIndex + 3).trim();

// Create a new Event object
Event eventTask = new Event(description, false, startTime, endTime);
tasksList.add(eventTask);

// Print confirmation message
System.out.println("Got it. I've added this task:");
System.out.println(" " + eventTask);
System.out.println("Now you have " + tasksList.size() + " tasks in the list");
} else {
System.out.println("Invalid input format for event command.");
}
} else {
System.out.println("added: " + command);
tasksList.add(new Tasks(command,false));
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Event extends Tasks {
private String startTime;
private String endTime;

public Event(String name, boolean isMarked, String startTime, String endTime) {
super(name, isMarked);
this.startTime = startTime;
this.endTime = endTime;
}

public String getStartTime() {
return startTime;
}

public void setStartTime(String startTime) {
this.startTime = startTime;
}

public String getEndTime() {
return endTime;
}

public void setEndTime(String endTime) {
this.endTime = endTime;
}

@Override
public String toString() {
String status = isMarked ? "[X]" : "[ ]";
return "[E]" + status + " " + name + " (from: " + startTime + " to: " + endTime + ")";
}
}
4 changes: 2 additions & 2 deletions src/main/java/Tasks.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public class Tasks {
private String name;
private boolean isMarked;
protected String name;
protected boolean isMarked;

public Tasks(String name, boolean isMarked) {
this.name = name;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Todo extends Tasks {

public Todo(String name, boolean isMarked) {
super(name, isMarked);
}




@Override
public String toString() {
if (isMarked) {
return "[T][X] " + name;
} else {
return "[T][ ] " + name;
}
}
}

0 comments on commit ed92cb2

Please sign in to comment.