-
Notifications
You must be signed in to change notification settings - Fork 270
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
[Ryan Chang Jia Jie] iP #292
base: master
Are you sure you want to change the base?
Changes from 58 commits
f0ac11a
2c93817
704e5b3
5068ebc
38fcffd
87d0d71
7b81057
3d16555
2770cef
12ba4e1
dff1c86
0b68584
a0a2092
d152a84
a5cd7ea
4288d48
f782ffb
37ab3af
ee2396d
0d0be9c
e45bca6
0a90fee
8ac0e8b
05cbe45
00f7fcf
432b9a4
89a002f
ab7e094
707ee94
116e09e
4c07809
1fe0728
3fc747d
1e6b55a
b7faffc
bc69135
a584d1b
0b735ca
716fed4
511d9cc
a425c4f
0c6eb74
6966e73
9052665
401156d
d36f543
2dbff74
d6a00f5
741d2b3
b72cae3
d18b829
184c942
352f494
ed56d8e
24820cd
3678626
9688666
32fb5c7
36a8484
9c60d76
78f3666
fb4dc79
58af730
9e3a9f8
78c8798
f82b7f1
6167f34
dbcfa44
b2245c5
14510b3
4302353
bd33ba3
03f19fd
a6d5116
cac8234
2dbdb6f
ccd7b8a
b8083b5
9f3f191
e0fc56f
6d80fda
bfba6da
d3774e3
ffb4306
9deaec7
23bfca1
1afd47a
d9d8baa
a550e3c
9efd004
4a51887
2782ffe
e2881fe
de14c4b
fed9f60
5feebec
c22f0ba
ce204e4
3ba2263
ba98855
e33d706
e9ae6aa
a27287d
827dfe9
1b474c0
80d93fc
edd0771
c6950de
6cb24d9
14676ee
3abc3e2
7634d94
7c93904
a5f267d
44ba29a
2a6484b
9d8c419
d8b449a
22e7c27
2e40a4a
31bfaa0
a163a68
8ac15d1
dc126ca
b0d1b89
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ bin/ | |
|
||
/text-ui-test/ACTUAL.txt | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
*.class |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.Scanner; | ||
|
||
public class Level1 { | ||
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. It might be better to use a more intuitive class name here! I noticed the same issue in other places too. |
||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
String line = " __________________________________________________\n"; | ||
System.out.println(line + " Hi there. I'm Siri \n" + " How may I help you? \n" + line); | ||
|
||
while(true) { | ||
String word = sc.next(); | ||
if (word.equals("bye")) { //print goodbye text | ||
System.out.println(line + " Goodbye.\n" + line); | ||
break; | ||
} else { //print whatever user inputed | ||
System.out.println(line + " " + word + "\n" + line); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
public class Level2 { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
ArrayList<String> arrList = new ArrayList<String>(); | ||
String line = " __________________________________________________\n"; | ||
System.out.println(line + " Hi there. I'm Siri \n" + " How may I help you? \n" + line); | ||
|
||
while(true) { | ||
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 it would be better to put spaces before the parenthesis? in adherence to the java coding standard. |
||
String word = sc.nextLine(); | ||
if (word.equals("bye")) { //print goodbye text | ||
System.out.println(line + " Goodbye.\n" + line); | ||
break; | ||
} else if (word.equals("list")) { //print all elements in a list with index in front | ||
System.out.print(line); | ||
int s = arrList.size(); | ||
for(int i = 0; i < s; i++) { | ||
System.out.println(" " + (i + 1) + ". " + arrList.get(i)); | ||
} | ||
System.out.println(line); | ||
} else { //print whatever user inputed with "added" infront | ||
arrList.add(word); | ||
System.out.println(line + " added: " + word + "\n" + line); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
public class Level3 { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
ArrayList<Task> arrList = new ArrayList<Task>(); | ||
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. Should |
||
String line = " __________________________________________________\n"; //print a line before greeting message | ||
System.out.println(line + " Hi there. I'm Siri \n" + " How may I help you? \n" + line); | ||
|
||
while (true) { //will keep querying user for input until user inputs "bye" into system | ||
String word = sc.next(); | ||
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 a more meaningful variable name would be easier to understand |
||
if (word.equals("bye")) { //print goodbye text and exit while loop,stop scanner from scanning | ||
System.out.println(line + " Goodbye.\n" + line); | ||
break; //end while loop | ||
} else if (word.equals("list")) { //print all elements in a list with index in front | ||
System.out.println(line + " Tasks to do:"); | ||
int s = arrList.size(); | ||
for (int i = 0; i < s; i++) { | ||
String currTask = arrList.get(i).toString(); | ||
System.out.println(" " + (i + 1) + "." + currTask); | ||
} | ||
System.out.println(line); | ||
} else if (word.equals("mark")) { | ||
int num = sc.nextInt(); | ||
int index = num - 1; | ||
Task t = arrList.get(index); | ||
t.markAsDone(); | ||
arrList.set(index, t); | ||
System.out.println(line + " This task has been marked:\n" | ||
+ " " + t.toString() + "\n" | ||
+ line); | ||
} else if (word.equals("unmark")) { | ||
int num = sc.nextInt(); | ||
int index = num - 1; | ||
Task t = arrList.get(index); | ||
t.markAsNotDone(); | ||
arrList.set(index, t); | ||
System.out.println(line + " This task has been unmarked:\n" | ||
+ " " + t.toString() + "\n" | ||
+ line); | ||
} else { //print everything user inputed with "added: " infront | ||
String restOfInput = sc.nextLine(); | ||
String taskToDo = word + restOfInput; | ||
Task t = new Task(taskToDo); | ||
arrList.add(t); | ||
System.out.println(line + " This task has been added to your list:\n" | ||
+ " added: " + taskToDo + "\n" | ||
+ line); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public class Task { | ||
String description; | ||
boolean isDone; | ||
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. Nice naming boolean convention that follows recommended guidelines |
||
|
||
public Task(String description) { //task constructor | ||
this.description = description; | ||
this.isDone = false; //initialise as false | ||
} | ||
|
||
public String getStatusIcon() { //will return either "X" or " " depending if task is done or not | ||
return isDone | ||
? "X" //if true mark with X | ||
: " "; //if false do not mark, leave as empty space | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void markAsNotDone() { | ||
this.isDone = false; | ||
} | ||
|
||
public String toString() { | ||
return "[" + this.getStatusIcon() + "] " + this.description; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Deadline extends Task { | ||
|
||
String deadline; | ||
|
||
public Deadline(String description, String deadline) { | ||
super(description); | ||
this.deadline = deadline; | ||
//find a way to scan deadline after description entered by user, maybe use the "/" as delimiter for the scanner? | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + "[" + this.getStatusIcon() + "]" + this.description + "(by:" + this.deadline + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Event extends Task { | ||
|
||
String eventDate; | ||
|
||
public Event(String description, String eventDate) { | ||
super(description); | ||
this.eventDate = eventDate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + "[" + this.getStatusIcon() + "]" + this.description + "(at:" + this.eventDate + ")"; | ||
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. Since this line is quite long, any reason why you did not wrap it on a new line? |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
public class Level4 { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
ArrayList<Task> arrList = new ArrayList<Task>(); | ||
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 changing the variable name to be more meaningful (e.g. taskList, tasks)? |
||
String line = " __________________________________________________\n"; //print a line before greeting message | ||
System.out.println(line + " Hi there. I'm Siri \n" + " How may I help you? \n" + line); | ||
|
||
while (true) { //will keep querying user for input until user inputs "bye" into system | ||
String word = sc.next(); | ||
if (word.equals("bye")) { //prints goodbye text and exit while loop,stop scanner from scanning | ||
System.out.println(line + " Goodbye.\n" + line); | ||
break; //end while loop | ||
} else if (word.equals("list")) { //prints all elements in a list with index in front | ||
System.out.println(line + " Tasks to do:"); | ||
int s = arrList.size(); | ||
for (int i = 0; i < s; i++) { | ||
String currTask = arrList.get(i).toString(); | ||
System.out.println(" " + (i + 1) + "." + currTask); | ||
} | ||
System.out.println(line); | ||
} else if (word.equals("mark")) { //marks the specified task with an "X" | ||
int num = sc.nextInt(); | ||
int index = num - 1; | ||
Task t = arrList.get(index); | ||
t.markAsDone(); | ||
arrList.set(index, t); | ||
System.out.println(line + " This task has been marked:\n " | ||
+ t.toString() + "\n" | ||
+ line); | ||
} else if (word.equals("unmark")) { //unmarks the specified task | ||
int num = sc.nextInt(); | ||
int index = num - 1; | ||
Task t = arrList.get(index); | ||
t.markAsNotDone(); | ||
arrList.set(index, t); | ||
System.out.println(line + " This task has been unmarked:\n " | ||
+ t.toString() + "\n" | ||
+ line); | ||
} else if (word.equals("todo")) { //creates todo task with "[T]" prefix and adds to the list | ||
String restOfInput = sc.nextLine(); | ||
String taskToDo = restOfInput; | ||
Todo t = new Todo(taskToDo); | ||
arrList.add(t); | ||
System.out.println(line + " This task has been added to your list:\n " | ||
+ t.toString() + "\n" + "\n" | ||
+ " Number of task(s) in your list: " + arrList.size() + "\n" | ||
+ line); | ||
} else if (word.equals("deadline")) { | ||
//creates deadline task with "[D]" prefix and deadline postfix and adds to list | ||
while (sc.hasNextLine()) { | ||
String[] userInput = sc.nextLine().split("/by"); | ||
// The userInput array now contains [taskDescription, deadline] | ||
Deadline deadLineTask = new Deadline(userInput[0], userInput[1]); | ||
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 on the clean code, however it might be better to avoid using magic numbers for better readability! |
||
arrList.add(deadLineTask); | ||
System.out.println(line + " This task has been added to your list:\n " | ||
+ deadLineTask.toString() + "\n" + "\n" | ||
+ " Number of task(s) in your list: " + arrList.size() + "\n" | ||
+ line); | ||
break; | ||
} | ||
} else if (word.equals("event")) { | ||
//creates event task with "[E]" prefix and event date postfix and adds to list | ||
while (sc.hasNextLine()) { | ||
String[] userInput = sc.nextLine().split("/at"); | ||
// The userInput array now contains [taskDescription, event date] | ||
Event eventTask = new Event(userInput[0], userInput[1]); | ||
arrList.add(eventTask); | ||
System.out.println(line + " This task has been added to your list:\n " | ||
+ eventTask.toString() + "\n" + "\n" | ||
+ " Number of task(s) in your list: " + arrList.size() + "\n" | ||
+ line); | ||
break; | ||
} | ||
} else { } //do nothing | ||
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. Maybe the last |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class Task { | ||
String description; | ||
boolean isDone; | ||
|
||
public Task(String description) { //task constructor | ||
this.description = description; | ||
this.isDone = false; //initialise as false | ||
} | ||
|
||
public String getStatusIcon() { //will return either "X" or " " depending if task is done or not | ||
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. it's good that you use verb/action to name the methods! |
||
return isDone | ||
? "X" //if true mark with X | ||
: " "; //if false do not mark, leave as empty space | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void markAsNotDone() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + this.getStatusIcon() + "] " + this.description; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class Todo extends Task { | ||
|
||
public Todo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + "[" + this.getStatusIcon() + "]" + this.description; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Deadline extends Task { | ||
|
||
String deadline; | ||
|
||
public Deadline(String description, String deadline) { | ||
super(description); | ||
this.deadline = deadline; | ||
//find a way to scan deadline after description entered by user, maybe use the "/" as delimiter for the scanner? | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + "[" + this.getStatusIcon() + "]" + this.description + "(by:" + this.deadline + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class EmptyDescException extends Exception { | ||
|
||
private String message; | ||
|
||
EmptyDescException(String message) { | ||
super(message); | ||
this.message = message; | ||
} | ||
|
||
public String toString() { | ||
return this.message; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Event extends Task { | ||
|
||
String eventDate; | ||
|
||
public Event(String description, String eventDate) { | ||
super(description); | ||
this.eventDate = eventDate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + "[" + this.getStatusIcon() + "]" + this.description + "(at:" + this.eventDate + ")"; | ||
} | ||
|
||
} |
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.
Perhaps adding a Javadoc for each class and public method?
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.
I agree that adding a Javadoc for each class and public method would allow the programme to be better understood