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

[Xu JiaChen]iP #60

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
98 changes: 92 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,96 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

// 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() {
// Logo string
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 :)");
System.out.println("What can I do for you?");
drawLine();
}

Choose a reason for hiding this comment

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

sufficiently comprehensible comments

// Method to handle the storage of tasks
public static void storeDude() {
// Initialize Scanner and ArrayList for tasks
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
ArrayList<Task> tasks = new ArrayList<>();
int curPos = 0; // Variable to keep track of the current task position

// Main loop to process commands
while (!(input.isEmpty())) {
drawLine();
if (input.equals("bye")) {
byeDude();
break;
} else if (input.equals("list")) {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < curPos; i++) {
System.out.println((i + 1) + ". " + tasks.get(i).getStatusIcon() + " " + tasks.get(i).description);
}
} else if (input.startsWith("mark") || input.startsWith("unmark")) {
// Split the input to separate command and task index
String[] arrOfInput = input.split(" ", 2);
Copy link

Choose a reason for hiding this comment

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

naming "arrOfInput" can be clearer to indicate that it stores the split of the input

if (arrOfInput.length < 2) {
System.out.println("Please specify the task index.");
} else {
try {
// Convert user input index to zero-based index for ArrayList
int index = Integer.parseInt(arrOfInput[1]) - 1;
if (index < 0 || index >= curPos) {
System.out.println("Task index out of range.");
} else {
// Mark or unmark the task
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).getStatusIcon() + " " + tasks.get(index).description);
}
} catch (NumberFormatException e) {
Copy link

Choose a reason for hiding this comment

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

try-catch statementfollows coding standard

System.out.println("Invalid task index format.");
}
}
} else {
// Add new task
System.out.println("added: " + input);
tasks.add(new Task(input));
curPos++;
}
drawLine();
input = scan.nextLine();
}
// Close the Scanner to prevent resource leak
scan.close();
}

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

// Main method

Choose a reason for hiding this comment

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

good use of encapsulation and methods of sufficient-length

public static void main(String[] args) {
hiDude();
storeDude();
}
}
17 changes: 17 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Task {
// Instance variables to store task description and status
protected String description;
protected boolean isDone;

// Constructor to initialize a task with a description
public Task(String description) {
this.description = description;
this.isDone = false;
}

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