Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ed3efe1
Add Dude Level 0
aaronxujiachen Aug 22, 2023
c6302e9
Add Dude Level 1
aaronxujiachen Sep 2, 2023
8d766a7
Add Dude Level 2
aaronxujiachen Sep 2, 2023
6eb2ef3
Add Dude Level 3
aaronxujiachen Sep 2, 2023
2cf44fb
Tweak the code to comply with coding standard
aaronxujiachen Sep 2, 2023
79f86ed
Add Dude Level 4
aaronxujiachen Sep 9, 2023
c310414
Improve Code Quality
aaronxujiachen Sep 9, 2023
dae8f4d
Rename Main Class
aaronxujiachen Sep 14, 2023
507e70b
Add Dude Level 5
aaronxujiachen Sep 16, 2023
47c336c
Merge branch 'branch-Level-5'
aaronxujiachen Sep 16, 2023
08a8f29
Organize All Classes Into A Package
aaronxujiachen Sep 16, 2023
4c76995
Merge branch 'branch-A-Packages'
aaronxujiachen Sep 16, 2023
317108a
Add Dude Level 6
aaronxujiachen Sep 20, 2023
898968d
Add Dude Level 7
aaronxujiachen Sep 21, 2023
564c8ee
Revert "Add Dude Level 7"
aaronxujiachen Sep 21, 2023
6a62116
Add Dude Level 7
aaronxujiachen Sep 21, 2023
45ac2de
Merge branch 'branch-Level-7'
aaronxujiachen Sep 21, 2023
12bfeb7
Refactor the code to make it more OOP
aaronxujiachen Sep 28, 2023
c2b4e7c
Add Dude Level 9
aaronxujiachen Sep 29, 2023
63adef5
Add Comments For Dude
aaronxujiachen Oct 2, 2023
c9d74d9
Merge pull request #2 from aaronxujiachen/branch-Level-9
aaronxujiachen Oct 3, 2023
7b95f42
Merge branch 'master' into branch-A-JavaDoc
aaronxujiachen Oct 3, 2023
3547e34
Merge pull request #3 from aaronxujiachen/branch-A-JavaDoc
aaronxujiachen Oct 3, 2023
64b0893
Resolve Merge Conflict
aaronxujiachen Oct 3, 2023
85bb25c
Update README.md
aaronxujiachen Oct 3, 2023
0d42444
Update README.md
aaronxujiachen Oct 3, 2023
76e80b4
Update README.md
aaronxujiachen Oct 3, 2023
a1189ae
Update UserGuide Website
aaronxujiachen Oct 5, 2023
c7dbfd9
Change the Path of dude.txt
aaronxujiachen Oct 5, 2023
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
17 changes: 17 additions & 0 deletions src/dude/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dude;

public class Deadline extends Task {
String by;

// Constructor to initialize a deadline with a description and a due date
public Deadline(String description, String by) {
super(description);
this.by = by;
this.type = "[D]"; // Type [D] indicates this is a dude.Deadline
}

@Override
public String toString() {
return getType() + getStatusIcon() + " " + description + " (by: " + by + ")";
}
}
181 changes: 181 additions & 0 deletions src/dude/Dude.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package dude;

import java.util.ArrayList;
import java.util.Scanner;

public class Dude {

// Method to draw horizontal lines
public static void drawLine() {
for (int i = 0; i < 30; i++) {
System.out.print("_");
}
System.out.println();
}

// Method to print the logo and introductory message
public static void hiDude() {
String logo = "### # \n"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this logo could be implemented as a constant.

+ "# # # \n"
+ "# # # # ### ## \n"
+ "# # # # # # # ## \n"
+ "# # # # # # ## \n"
+ "### ### ### ## \n";

System.out.println("Hello from\n" + logo);
drawLine();
System.out.println("Hello! I'm your best dude.Dude :)");
System.out.println("What can I do for you?");
drawLine();
}

// Method to handle the storage of tasks
public static void storeDude() {
Scanner scan = new Scanner(System.in);
ArrayList<Task> tasks = new ArrayList<>();

String input = scan.nextLine();
while (!input.isEmpty()) {
drawLine();

try {
if (input.equals("bye")) {
byeDude();
break;
} else if (input.equals("list")) {
listTasks(tasks);
} else if (input.startsWith("todo")) {
addTodoTask(tasks, input);
} else if (input.startsWith("deadline")) {
addDeadlineTask(tasks, input);
} else if (input.startsWith("event")) {
addEventTask(tasks, input);
} else if (input.startsWith("mark") || input.startsWith("unmark")) {
markOrUnmarkTask(tasks, input);
} else {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
} catch (DudeException e) {
System.out.println(e.getMessage());
}

drawLine();
input = scan.nextLine();
}
scan.close();
}


private static void listTasks(ArrayList<Task> tasks) {
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));
}
}

private static void addTodoTask(ArrayList<Task> tasks, String input) throws DudeException {
if (input.length() <= 5) {
throw new DudeException("☹ OOPS!!! The description of a todo cannot be empty.");
}

String taskDescription = input.substring(5).trim();
if (taskDescription.isEmpty()) {
throw new DudeException("☹ OOPS!!! The description of a todo cannot be empty.");
}
tasks.add(new Task(taskDescription));
printAddedTask(tasks);
}


private static void addDeadlineTask(ArrayList<Task> tasks, String input) throws DudeException {
int byIndex = input.indexOf("/by");
if (byIndex == -1) {
throw new DudeException("☹ OOPS!!! Please specify a deadline using /by.");
}

String taskDescription = input.substring(9, byIndex).trim();
if (taskDescription.isEmpty()) {
throw new DudeException("☹ OOPS!!! The description of a deadline cannot be empty.");
}

String by = input.substring(byIndex + 4).trim();
if (by.isEmpty()) {
throw new DudeException("☹ OOPS!!! The deadline time cannot be empty.");
}

tasks.add(new Deadline(taskDescription, by));
printAddedTask(tasks);
}

private static void addEventTask(ArrayList<Task> tasks, String input) throws DudeException {
int fromIndex = input.indexOf("/from");
int toIndex = input.indexOf("/to");

if (fromIndex == -1 || toIndex == -1) {
throw new DudeException("☹ OOPS!!! Please specify event time using /from and /to.");
}

String taskDescription = input.substring(6, fromIndex).trim();
if (taskDescription.isEmpty()) {
throw new DudeException("☹ OOPS!!! The description of an event cannot be empty.");
}

String from = input.substring(fromIndex + 6, toIndex).trim();
if (from.isEmpty()) {
throw new DudeException("☹ OOPS!!! The start time of an event cannot be empty.");
}

String to = input.substring(toIndex + 4).trim();
if (to.isEmpty()) {
throw new DudeException("☹ OOPS!!! The end time of an event cannot be empty.");
}

tasks.add(new Event(taskDescription, from, to));
printAddedTask(tasks);
}

private static void markOrUnmarkTask(ArrayList<Task> tasks, String input) {
String[] arrOfInput = input.split(" ", 2);
if (arrOfInput.length < 2) {
System.out.println("Please specify the task index.");
return;
}

try {
int index = Integer.parseInt(arrOfInput[1]) - 1;
if (index < 0 || index >= tasks.size()) {
System.out.println("dude.Task index out of range.");
return;
}
tasks.get(index).isDone = input.startsWith("mark");
String message = input.startsWith("mark") ?
"Nice! I've marked this task as done:" :
"OK, I've marked this task as not done yet:";
System.out.println(message);
System.out.println(" " + tasks.get(index));
} catch (NumberFormatException e) {
System.out.println("Invalid task index format.");
}
}

private static void printAddedTask(ArrayList<Task> tasks) {
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + (tasks.size() == 1 ? " task" : " tasks") + " in the list.");
}



// Method to print the goodbye message
public static void byeDude() {
System.out.println("Bye. Hope to see you again soon!");
drawLine();
}

// Main method
public static void main(String[] args) {
hiDude();
storeDude();
}
}

7 changes: 7 additions & 0 deletions src/dude/DudeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dude;

public class DudeException extends Exception {
public DudeException(String message) {
super(message);
}
}
19 changes: 19 additions & 0 deletions src/dude/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dude;

public class Event extends Task {
String startDate;
String endDate;

// Constructor to initialize an event with a description, start date, and end date
public Event(String description, String startDate, String endDate) {
super(description);
this.startDate = startDate;
this.endDate = endDate;
this.type = "[E]"; // Type [E] indicates this is an dude.Event
}

@Override
public String toString() {
return getType() + getStatusIcon() + " " + description + " (from: " + startDate + " to: " + endDate + ")";
}
}
29 changes: 29 additions & 0 deletions src/dude/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dude;

public class Task {
// Instance variables to store task description and status
protected String description;
protected boolean isDone;
protected String type;

// Constructor to initialize a task with a description
public Task(String description) {
this.description = description;
this.isDone = false;
this.type = "[T]"; // Default type is [T]
}

public String getType() {
return type;
}

// Method to get the status icon based on whether the task is done or not
public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]");
}

@Override
public String toString () {
return getType() + getStatusIcon() + " " + description;
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.