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

[Tze Loong] iP #213

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7558b46
Level 0 Greet
TzeLoong Feb 1, 2023
dbc5dac
Level 1. Greet, Echo, Exit
TzeLoong Feb 1, 2023
f808559
Level 2. Add, List
TzeLoong Feb 1, 2023
50aad95
Level-3
TzeLoong Feb 2, 2023
312117e
Update Tasks.java
TzeLoong Feb 2, 2023
98bc638
Coding Standard
TzeLoong Feb 2, 2023
2306a2a
Level-4
TzeLoong Feb 9, 2023
cb74c50
Level-4
TzeLoong Feb 16, 2023
fe13d52
Level-4
TzeLoong Feb 17, 2023
f5259c3
Create Duke.jar
TzeLoong Feb 17, 2023
dc3b488
Delete Duke.jar
TzeLoong Feb 17, 2023
7b1e715
Handle errors
TzeLoong Feb 18, 2023
88c2683
Use of ArrayList<Task>
TzeLoong Feb 18, 2023
1712749
Delete
TzeLoong Feb 18, 2023
de06295
Save
TzeLoong Feb 27, 2023
3b1d6d4
Save
TzeLoong Feb 27, 2023
409496b
Level-7
TzeLoong Feb 27, 2023
8c09680
Level-7
TzeLoong Feb 28, 2023
d44a21d
Level-9
TzeLoong Feb 28, 2023
1e53d33
Added comments
TzeLoong Feb 28, 2023
2b06b30
Added JavaDoc comments
TzeLoong Feb 28, 2023
9a1c515
Merge pull request #1 from TzeLoong/A-JavaDoc
TzeLoong Feb 28, 2023
57076f4
Changes
TzeLoong Mar 1, 2023
b847776
Changes
TzeLoong Mar 1, 2023
c8ce553
Changes
TzeLoong Mar 1, 2023
6df5295
Changes
TzeLoong Mar 2, 2023
212cf99
Updated userguide
TzeLoong Mar 3, 2023
7e9c93f
Update Tasklist.java
TzeLoong Mar 3, 2023
b624d2a
Merge branch 'master' of https://github.com/TzeLoong/ip
TzeLoong Mar 3, 2023
6009396
Added comments
TzeLoong Mar 3, 2023
da04bb5
Create ip.jar
TzeLoong Mar 3, 2023
c7ddfbe
Improvements for v2-updated
TzeLoong Mar 19, 2023
1ad8a59
Improvements for v0.2-updated
TzeLoong Mar 19, 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
Binary file added src/main/java/Duke.class
Binary file not shown.
71 changes: 69 additions & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,77 @@
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {

Choose a reason for hiding this comment

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

Consistent 4 spaces indent throughout the code, good job


public static void greet_user() {
System.out.println("Hello! I'm Duke \n");
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println(logo);
System.out.println("How can i help u? \n");
}

public static void echo() {

Choose a reason for hiding this comment

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

Good job for using a verb to name this method

Scanner scan = new Scanner(System.in);

String input = scan.next();
if ("bye".equals(input)) {
System.out.println("Goodbye. Hope to see u again :) \n");
} else {
System.out.println(input);
echo();
}

scan.close();

}

public static void main(String[] args) {

Choose a reason for hiding this comment

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

Try keeping your main method short and have a parser to deal with interpreting user commands instead

greet_user();

Choose a reason for hiding this comment

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

Good job on extracting this part as a separate function

int counter = 0;

Tasks[] list_of_tasks = new Tasks[101]; // Following the assumption that there will be no more than 100 tasks

Choose a reason for hiding this comment

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

Perhaps you try using camelcase when naming variables. Eg. listOfTasks

Choose a reason for hiding this comment

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

It may be better to avoid using a magic number (100) and instead define it at the top of the file as MAX_NUMBER_OF_TASKS

for (int k = 0; k < 101; k++) {
list_of_tasks[k] = new Tasks("");
}

Scanner scan = new Scanner(System.in);
String input = scan.nextLine();

while (!"bye".equals(input)) {
if ("list".equals(input)) {
System.out.println("Here are the tasks in your list: ");
for (int i = 0; i < counter; i++) {
System.out.println(
i + 1 + "." + " " + list_of_tasks[i].getStatusIcon() + " " + list_of_tasks[i].description);
}

Choose a reason for hiding this comment

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

It may be clearer to extract these parts as separate functions to avoid nesting loops.

} else if (input.length() >= 4 && input.substring(0, 4).equals("mark")) {
Integer index = Integer.valueOf(input.substring(5, input.length()));
list_of_tasks[index - 1].markAsDone();
System.out.println("Nice! This task is completed");
System.out
.println(list_of_tasks[index - 1].getStatusIcon() + " " + list_of_tasks[index - 1].description);
} else if (input.length() >= 6 && input.substring(0, 6).equals("unmark")) {
Integer index = Integer.valueOf(input.substring(7, input.length()));
list_of_tasks[index - 1].markAsUnDone();
System.out.println("Ok, This task is still not complete");
System.out
.println(list_of_tasks[index - 1].getStatusIcon() + " " + list_of_tasks[index - 1].description);
} else {
System.out.println("added: " + input);
list_of_tasks[counter].description = input;
list_of_tasks[counter].isDone = false;
counter++;
}
scan = new Scanner(System.in);
input = scan.nextLine();

Choose a reason for hiding this comment

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

Since you abstracted the [greet_user()] function, it may be better if you maintain Single Level of Abstraction Principle (SLAP), and also extract this portion as a separate function


}

System.out.println("Goodbye. Hope to see u again :) \n");
scan.close();
}

}
Binary file added src/main/java/Tasks.class
Binary file not shown.
23 changes: 23 additions & 0 deletions src/main/java/Tasks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Tasks {

Choose a reason for hiding this comment

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

Perhaps you could name this class as "Task" (singular) instead as it refers to one task


protected String description;
protected boolean isDone;

public Tasks(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 markAsUnDone() {
this.isDone = false;
}

}