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

[Jia Juin] iP #50

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
73 changes: 56 additions & 17 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;

public class Duke {

public static Task getTheTask(ArrayList<Task> List, int j)
{
return List.get(j);
}
Copy link

Choose a reason for hiding this comment

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

The brackets for your methods should follow the Egyptian style (aka K&R). I see you have followed the bracket coding style in Tasks.java.
To illustrate this,
while (!done) {
doSomething();
done = moreToDo();
}


public static void addTask(String description, ArrayList<Task> List)
{
Task t = new Task(description);
List.add(t);
}

public static void updateCommand(Task task, ArrayList<Task> List, int count)
{
List.set(count,task);
}

public static void main(String[] args) {
System.out.println("Hello ! I'm Duke\n");
System.out.println("What can I do for you ? \n");

String command;
int i = 0;
String[] list = new String[100];
ArrayList<Task> list = new ArrayList<>();
Scanner in = new Scanner (System.in);
command = in.nextLine();
String option_1 = "bye";
Copy link

Choose a reason for hiding this comment

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

Your string name could be more precise. To illustrate what I mean, perhaps you could use commandByeWord?
For instance,
String commandByeWord = "bye";

String option_2 = "list";
String option_3 = "done";

while (true)
{
// cannot use in.nextLine() since it will treat (done (taskNumber)) as one string
// thus will not lead us to the done statement
command = in.next();

if (command.equals(option_1))
{
System.out.println("------------------------");
Copy link

Choose a reason for hiding this comment

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

Perhaps you can put the constant strings as constants. For example,
private static final String LINE_BREAK = "----------------------------------------";

Expand All @@ -27,25 +46,45 @@ public static void main(String[] args) {
else if (command.equals(option_2))
{
System.out.println("------------------------");

for (int j = 0; j < i; j++)
int count = 1;
System.out.println(" Here are the tasks in your list: ");
for (Task t : list)
{
System.out.print(j+1);
System.out.print(". ");
System.out.println(list[j]);
System.out.print(count);
System.out.print(".[");
System.out.print(t.getStatusIcon());
System.out.print("]");
System.out.println(t.description);
count++;
}

System.out.println("------------------------");
command = in.nextLine();
}
else if (command.equals(option_3))
{
int taskNumber = in.nextInt();
Task t = getTheTask(list,taskNumber-1);
t.markAsDone();
updateCommand(t,list,taskNumber-1);
System.out.println("------------------------------------------");
System.out.print("Nice! I've marked this task as done: [");
System.out.print(t.getStatusIcon());
System.out.print("]");
System.out.println(t.description);
System.out.println("------------------------------------------");
}
else
{
list[i] = command;
System.out.println("------------------------");
System.out.println("Added: " + command);
System.out.println("------------------------");
i++;
command = in.nextLine();
// if there is no "done", "bye", "list" in the string
Copy link

Choose a reason for hiding this comment

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

Good attempt of explaining choice of use of next line of code.

String splitter = in.nextLine();
// concat() method returns a String with the value of the String passed into the method,
Copy link

Choose a reason for hiding this comment

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

Good explanation of methods for non-technical users! Also, the indentation for comments is observed.

// appended to the end of the String, used to invoke this method.
command = command.concat(splitter);
addTask(command,list);
Task newAddCommand = getTheTask(list, list.size()-1);
System.out.println("-------------------------------------");
System.out.print("Successfully added: ");
System.out.println(newAddCommand.description);
System.out.println("--------------------------------------");
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
Copy link

Choose a reason for hiding this comment

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

Good job! the names for the methods are well done.

this.description = description;
this.isDone = false;
}

public String getDescription() {
return description;
}

public boolean isDone() {
return isDone;
}

public void setDescription(String description) {
this.description = description;
}

public void markAsDone() {
isDone = true;
}

public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols
}
}