-
Notifications
You must be signed in to change notification settings - Fork 186
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
[shawnpong] iP #178
base: master
Are you sure you want to change the base?
[shawnpong] iP #178
Changes from 8 commits
55f9f9f
f837ddb
a6f7324
acf8fdf
623f216
46afd35
66efd52
8cb1b88
a37a35f
5195542
118c2de
0e1e695
ea1adcb
2d89f52
190535f
14cbebb
f6e276f
a2c95c2
3fd63f3
52ab77b
4894ef2
3992ded
4293c01
a67bf9b
46d6cc1
d3003ef
0c702d7
aa38640
2288a85
db336b4
c8b6a97
c6a0097
e7bc46d
19e3ebf
f45955d
02ec784
6f0f9e7
00aadd0
8d5f63a
c7abf86
bb716bf
8dc40dc
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Deadline extends Task { | ||
|
||
protected String by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D] " + super.getStatusIcon() + " " + super.toString() + " (by: " + by + ")"; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Events extends Task { | ||
|
||
protected String from; | ||
protected String to; | ||
|
||
public Events(String description, String from, String to) { | ||
super(description); | ||
this.from = from; | ||
this.to = to; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E] " + super.getStatusIcon() + " " + super.toString() + " (from: " + from + " to: " + to + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import java.util.Scanner; | ||
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. I like how you specified java.util.Scanner instead of java.util.* , this complies with coding standards, well done ! |
||
|
||
public class Floda { | ||
public static void main(String[] args) { | ||
shawnpong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String name = "Floda"; | ||
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. Redundant code as it can be combined with the next line 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 this be a constant? And if it was then perhaps you could have used (public static final string) and capitalised the variable name (NAME) to follow the coding standards. |
||
System.out.println("Hello! I'm " + name); | ||
Task[] list = new Task[100]; | ||
int taskCounter = 0; | ||
Scanner scanner = new Scanner(System.in); | ||
String line; | ||
System.out.println("I can keep track of a to-do list for you! Just type what you want to add to the list."); | ||
while (!"bye".equals((line = scanner.nextLine()))) { | ||
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 would improve readability if you directly assigned String line = scanner.nextLine() in the previous line instead of assigning it inside the conditional for the while loop. Then you could read in a new line of input at the end of every if else block. |
||
if ("list".equals(line)) { | ||
System.out.println("List so far: "); | ||
for (int i = 0; i < taskCounter; i++) { | ||
System.out.println((i + 1) + "." + list[i]); | ||
} | ||
} else if (line.startsWith("mark")) { | ||
Scanner taskScanner = new Scanner(line); | ||
taskScanner.next(); | ||
if (taskScanner.hasNextInt()) { | ||
int taskNumber = taskScanner.nextInt() - 1; | ||
if (taskNumber >= 0 && taskNumber < taskCounter) { | ||
list[taskNumber].setDone(true); | ||
System.out.println("I have marked this task as done:\n" + list[taskNumber]); | ||
} else { | ||
System.out.println("Invalid task number! Please check with 'list'."); | ||
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 could refactor the code into smaller methods that handle the logic without having to have so many levels of nesting, this would make the code more readable. |
||
} | ||
} else { | ||
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. Avoid arrowhead style code |
||
System.out.println("Invalid input! Please check with 'list'."); | ||
} | ||
} else if (line.startsWith("unmark")) { | ||
Scanner taskScanner = new Scanner(line); | ||
taskScanner.next(); | ||
if (taskScanner.hasNextInt()) { | ||
int taskNumber = taskScanner.nextInt() - 1; | ||
if (taskNumber >= 0 && taskNumber < taskCounter) { | ||
list[taskNumber].setDone(false); | ||
System.out.println("I have marked this task as not done:\n" + list[taskNumber]); | ||
} else { | ||
System.out.println("Invalid task number! Please check with 'list'."); | ||
} | ||
} else { | ||
System.out.println("Invalid input! Please check with 'list'."); | ||
} | ||
} else if (line.startsWith("deadline")) { | ||
Scanner taskScanner = new Scanner(line); | ||
taskScanner.next(); | ||
String remaining = taskScanner.nextLine().trim(); | ||
String[] parts = remaining.split("/by"); | ||
String description = parts[0].trim(); | ||
String by = parts[1].trim(); | ||
list[taskCounter] = new Deadline(description, by); | ||
taskCounter++; | ||
System.out.println("Added: " + list[taskCounter - 1] + "\nNow you have " + (taskCounter) + " items in the list!"); | ||
} else if (line.startsWith("todo")) { | ||
Scanner taskScanner = new Scanner(line); | ||
taskScanner.next(); | ||
String remaining = taskScanner.nextLine().trim(); | ||
list[taskCounter] = new ToDo(remaining); | ||
taskCounter++; | ||
System.out.println("Added: " + list[taskCounter - 1] + "\nNow you have " + (taskCounter) + " items in the list!"); | ||
} else if (line.startsWith("event")) { | ||
Scanner taskScanner = new Scanner(line); | ||
taskScanner.next(); | ||
String remaining = taskScanner.nextLine().trim(); | ||
remaining = remaining.replace("/to", "/from"); | ||
String[] parts = remaining.split("/from"); | ||
String description = parts[0].trim(); | ||
String from = parts[1].trim(); | ||
String to = parts[2].trim(); | ||
list[taskCounter] = new Events(description, from, to); | ||
taskCounter++; | ||
System.out.println("Added: " + list[taskCounter - 1] + "\nNow you have " + (taskCounter) + " items in the list!"); | ||
} else { | ||
list[taskCounter] = new Task(line); | ||
taskCounter++; | ||
System.out.println("Added: " + line + "\nNow you have " + (taskCounter) + " items in the list!"); | ||
} | ||
} | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
} |
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. Could consider refactoring to use separate methods to handle individual command types. For example, if the command is "event" you could use a handleEventInput() method to parse the string and add the object to the list. This will improve readability considerably. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public 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. I like how the boolean method isDone is namd to sound like a boolean! |
||
return isDone; | ||
} | ||
|
||
public void setDone(boolean done) { | ||
isDone = done; | ||
} | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "[X]" : "[ ]"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return description; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ToDo extends Task { | ||
|
||
public ToDo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T] " + super.getStatusIcon() + " " + super.toString(); | ||
} | ||
} |
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.
Great use of Override annotation to signal method overriding