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

[tiffanyliu0220] iP #185

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5067e11
Week 2
tiffanyliu0220 Feb 7, 2024
c688996
Week 3
tiffanyliu0220 Feb 7, 2024
1bfdf54
Week 3
tiffanyliu0220 Feb 7, 2024
9c1c488
Week 4
tiffanyliu0220 Mar 4, 2024
4dd35ac
Level-5
tiffanyliu0220 Mar 7, 2024
ebc535d
Merge branch 'branch-Level-5'
tiffanyliu0220 Mar 7, 2024
16b5032
Level-6
tiffanyliu0220 Mar 7, 2024
1d963eb
A-Collections
tiffanyliu0220 Mar 7, 2024
629cd1c
Level-7
tiffanyliu0220 Mar 8, 2024
3fbfe84
Merge branch 'branch-Level-7'
tiffanyliu0220 Mar 8, 2024
4947b3a
still working on more oop
tiffanyliu0220 Mar 9, 2024
386d459
A-MoreOOP
tiffanyliu0220 Mar 9, 2024
00466b8
Level-9
tiffanyliu0220 Mar 10, 2024
23fc241
Merge pull request #1 from tiffanyliu0220/branch-Level-9
tiffanyliu0220 Mar 10, 2024
8ed0d1c
Merge branch 'branch-Level-9'
tiffanyliu0220 Mar 10, 2024
0ab06aa
A-JavaDoc
tiffanyliu0220 Mar 10, 2024
945178a
Merge branch 'master' of https://github.com/tiffanyliu0220/ip
tiffanyliu0220 Mar 10, 2024
34fa31a
A-CodeQuality
tiffanyliu0220 Mar 10, 2024
f1598b1
Update README feature of adding task.md
tiffanyliu0220 Mar 10, 2024
8794be4
Update README feature of adding task.md
tiffanyliu0220 Mar 10, 2024
ab1611b
Update README feature 2 of viewing task list.md
tiffanyliu0220 Mar 10, 2024
391800e
Update README.md
tiffanyliu0220 Mar 10, 2024
00dce25
Update README.md
tiffanyliu0220 Mar 10, 2024
1e754db
Update README feature 3 mark/unmark task as done.md
tiffanyliu0220 Mar 10, 2024
db0c247
Update README feature - find tasks.md
tiffanyliu0220 Mar 10, 2024
0ea728b
Update README feature load, save and display data.md
tiffanyliu0220 Mar 10, 2024
7a09af6
Update README.md
tiffanyliu0220 Mar 10, 2024
405b601
Update README feature - delete task.md
tiffanyliu0220 Mar 10, 2024
435b546
Update README feature - greet and exit.md
tiffanyliu0220 Mar 10, 2024
2ffffed
Update README.md
tiffanyliu0220 Mar 10, 2024
422a21d
Update README.md
tiffanyliu0220 Mar 10, 2024
b2ba144
Update README.md
tiffanyliu0220 Mar 10, 2024
6686ca4
Update README.md
tiffanyliu0220 Mar 10, 2024
2633fbb
Merge branch 'master' of https://github.com/tiffanyliu0220/ip
tiffanyliu0220 Mar 10, 2024
fcf59b1
no message
tiffanyliu0220 Mar 10, 2024
879520a
no message
tiffanyliu0220 Mar 10, 2024
72e4710
Update README.md
tiffanyliu0220 Mar 10, 2024
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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

109 changes: 109 additions & 0 deletions src/main/java/Sunny.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import java.util.Scanner;

public class Sunny {
public static void main(String[] args) {
String chatBotName = "Sunny";
Task[] tasks = new Task[100]; //Fixed-size array to store tasks
int counter = 0; //Counter to keep track of the number of tasks
Copy link

Choose a reason for hiding this comment

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

Good job in adding comments so the readers know what they are reading!


//Greets the user
System.out.println("Hello! I'm " + chatBotName);
System.out.println("What can I do for you?");
System.out.println(" ");

//Initialises scanner for user input
Scanner scanner = new Scanner(System.in);

//Echoes commands after user says bye
while (true) {
//Gets user input

Choose a reason for hiding this comment

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

Goodjob on indenting the comments correctly!

String command = scanner.nextLine();

//If the user input is "bye"
if (command.equalsIgnoreCase("bye")){

Choose a reason for hiding this comment

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

Add a space after before the opening brace.
e.g "if (condition) {" instead of "if (condition){"
same for other if else and else if statements

//Exit message
System.out.println(" ");
System.out.println("Bye. Hope to see you again soon!");
System.out.println(" ");
break;
} else if (command.equalsIgnoreCase("list")){
//Displays the list of tasks
System.out.println("Here are the tasks in your list: ");
for (int i = 0; i < counter; i ++) {

Choose a reason for hiding this comment

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

i++ instead of i ++

//

Choose a reason for hiding this comment

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

Clean up code to remove random comments

System.out.println((i + 1) + ". [" + tasks[i].getStatusIcon() + "]" + tasks[i].getDescription());
}
System.out.println(" ");
} else if (command.startsWith("mark")){
//Mark a task as done
int taskIndex = extractTaskIndex(command);
if (taskIndex > 0 && taskIndex <= counter) {
tasks[taskIndex - 1].markAsDone();
System.out.println("Nice! I've marked this task as done:");
System.out.println("[" + tasks[taskIndex - 1].getStatusIcon() + "] " + tasks[taskIndex - 1].getDescription());

Choose a reason for hiding this comment

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

Maybe can consider wrapping lines for longer codes :)

} else {
System.out.println("Invalid task index. Please provide a valid task index.");

}
System.out.println(" ");
} else if (command.startsWith("unmark")){
// Mark a task as not done
int taskIndex = extractTaskIndex(command);
if (taskIndex > 0 && taskIndex <= counter) {
tasks[taskIndex - 1].unmarkAsDone();
System.out.println("OK, I've marked this task as not done yet:");
System.out.println("[" + tasks[taskIndex - 1].getStatusIcon() + "] " + tasks[taskIndex - 1].getDescription());
} else {
System.out.println(" Invalid task index. Please provide a valid task index.");
}
System.out.println(" ");

Choose a reason for hiding this comment

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

Perhaps you could separate each cases into different methods to make the method shorter.

} else {
//Display the added task message
System.out.println("added: " + command);
System.out.println(" ");

//Add the command to the tasks array
tasks[counter] = new Task(command);
counter++;
}
}
//Close the scanner
scanner.close();
}

// Helper method to extract the task index from commands like "mark 2"
private static int extractTaskIndex(String command) {
try {
return Integer.parseInt(command.split(" ")[1]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
return -1;
}
}
}
Copy link

Choose a reason for hiding this comment

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

Good job in adding an error prompt so that the users know what goes wrong.


// Task class to represent tasks
class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public void markAsDone() {
this.isDone = true;
}

public void unmarkAsDone() {
this.isDone = false;
}

public String getDescription() {
return description;
}
}