-
Notifications
You must be signed in to change notification settings - Fork 73
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
base: master
Are you sure you want to change the base?
[Jia Juin] iP #50
Changes from 1 commit
9570590
694acbb
0ea94ba
f5475ad
b3c6870
f1ac186
98f8a6d
2889871
e032e70
75452fa
158f457
1409a2a
ec880be
f074ee3
60f8c55
b120dae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
|
||
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
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("------------------------"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps you can put the constant strings as constants. For example, |
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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("--------------------------------------"); | ||
} | ||
} | ||
|
||
|
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} |
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.
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();
}