-
Notifications
You must be signed in to change notification settings - Fork 76
[Xu JiaChen]iP #60
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
Open
aaronxujiachen
wants to merge
29
commits into
nus-cs2113-AY2324S1:master
Choose a base branch
from
aaronxujiachen:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Xu JiaChen]iP #60
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 c6302e9
Add Dude Level 1
aaronxujiachen 8d766a7
Add Dude Level 2
aaronxujiachen 6eb2ef3
Add Dude Level 3
aaronxujiachen 2cf44fb
Tweak the code to comply with coding standard
aaronxujiachen 79f86ed
Add Dude Level 4
aaronxujiachen c310414
Improve Code Quality
aaronxujiachen dae8f4d
Rename Main Class
aaronxujiachen 507e70b
Add Dude Level 5
aaronxujiachen 47c336c
Merge branch 'branch-Level-5'
aaronxujiachen 08a8f29
Organize All Classes Into A Package
aaronxujiachen 4c76995
Merge branch 'branch-A-Packages'
aaronxujiachen 317108a
Add Dude Level 6
aaronxujiachen 898968d
Add Dude Level 7
aaronxujiachen 564c8ee
Revert "Add Dude Level 7"
aaronxujiachen 6a62116
Add Dude Level 7
aaronxujiachen 45ac2de
Merge branch 'branch-Level-7'
aaronxujiachen 12bfeb7
Refactor the code to make it more OOP
aaronxujiachen c2b4e7c
Add Dude Level 9
aaronxujiachen 63adef5
Add Comments For Dude
aaronxujiachen c9d74d9
Merge pull request #2 from aaronxujiachen/branch-Level-9
aaronxujiachen 7b95f42
Merge branch 'master' into branch-A-JavaDoc
aaronxujiachen 3547e34
Merge pull request #3 from aaronxujiachen/branch-A-JavaDoc
aaronxujiachen 64b0893
Resolve Merge Conflict
aaronxujiachen 85bb25c
Update README.md
aaronxujiachen 0d42444
Update README.md
aaronxujiachen 76e80b4
Update README.md
aaronxujiachen a1189ae
Update UserGuide Website
aaronxujiachen c7dbfd9
Change the Path of dude.txt
aaronxujiachen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 + ")"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| + "# # # \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(); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 + ")"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.