-
Notifications
You must be signed in to change notification settings - Fork 187
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
[Liu Ze Hui] iP #192
base: master
Are you sure you want to change the base?
[Liu Ze Hui] iP #192
Changes from 6 commits
215dbb8
da5bbbb
5b9ead6
bec25f4
6c1ed56
5769d82
52ab112
09dad06
8934c19
5667b2a
4c010a4
1163469
ca4c4c6
755cb31
75014ee
e3469f4
96d7ab0
6e92e2d
058b7df
1f259ca
666aaa8
12b1ddd
09c7795
ed304d3
a5c5aed
0612989
2df056b
db07c45
f540c91
df0007c
6a14058
8c65295
84af7ed
306396e
674d503
017bdec
302e239
5491c80
5fd1291
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,12 @@ | ||
public class Deadline extends Task { | ||
protected String by; | ||
|
||
public Deadline (String description, String by){ | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
public String toString() { | ||
return "[D] " + super.toString() + " (by: " + by + ")"; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||||||||||||||||||||||||||||
import static com.sun.beans.introspect.PropertyInfo.Name.description; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public class Event extends Task{ | ||||||||||||||||||||||||||||||||||
private String at; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public Event (String description, String at){ | ||||||||||||||||||||||||||||||||||
super(); | ||||||||||||||||||||||||||||||||||
this.at = at; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public String getAt(){ | ||||||||||||||||||||||||||||||||||
return at; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public String toString() { | ||||||||||||||||||||||||||||||||||
return "[E] " + super.toString() + description + " (at: " + at + ")"; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
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 is usually a practise to use This change can be made at other places as well :)
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class Task { | ||
protected static String[] tasks = new String[100]; | ||
protected static boolean[] tasksCompleted = new boolean[100]; | ||
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. whichTasksCompleted sounds like a better variable name as the variable name tasksCompleted sounds like an integer 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. Please avoid the use of Magic Numbers. Instead declare a constant with the value you deem is right, and use that constant. Or better, you may choose to use 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. For this line, I may suggest you to refactor Sometimes it may happen that, you delete a protected boolean isTaskDone; |
||
protected static int taskNumber; | ||
|
||
public Task(String description) { | ||
taskNumber = 0; | ||
} | ||
|
||
public static void addTask(String userInput) { | ||
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 the way you named your methods, which are all in camalCase. Good job! |
||
tasks[taskNumber] = userInput; | ||
tasksCompleted[taskNumber] = false; | ||
taskNumber++; | ||
} | ||
public static void markDone(int taskNumber) { | ||
tasksCompleted[taskNumber] = true; | ||
} | ||
|
||
public static void markUndone(int taskNumber) { | ||
tasksCompleted[taskNumber] = false; | ||
} | ||
public static String getStatusIcon(int taskNumber) { | ||
return (tasksCompleted[taskNumber] ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public static void printList() { | ||
for(int i = 0; i < taskNumber; i++) { | ||
System.out.println(i+1 + ". [" + getStatusIcon(i) + "] " + tasks[i]); | ||
} | ||
Yoj.printLine(); | ||
} | ||
} |
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); | ||
} | ||
|
||
// Prints task | ||
public void printTask(){ | ||
System.out.print("[T]["); | ||
|
||
System.out.println("] " + 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. Missing EOF. Add an extra empty line at the end of file (EOF), as this indicates the end of the file. You may configure IntelliJ to add this automatically for you when hit |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import java.util.Scanner; | ||
//so scanner class can be used | ||
|
||
public class Yoj { | ||
public static void printLine() { | ||
System.out.println("________________________________________"); | ||
} | ||
public static void printShortLine() { | ||
System.out.println("_____________"); | ||
} | ||
public static void printHello() { | ||
String logo = | ||
"__ __ ___ _____ \n" | ||
+ "\\ \\ / / / _ \\ | ___ |\n" | ||
+ " \\ Y / | | | | | | \n" | ||
+ " \\ / | | | | | | \n" | ||
+ " | | | |_| | ___| | \n" | ||
+ " |_| \\___/ |____/ \n"; | ||
printLine(); | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println("Hello! I'm YOJ"); | ||
System.out.println("What can I do for you?"); | ||
printLine(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
printHello(); | ||
// get user input | ||
Scanner in = new Scanner(System.in); | ||
String userInput; | ||
userInput = in.nextLine(); | ||
|
||
while(!userInput.equals("bye")) { | ||
printShortLine(); | ||
System.out.println("added: " + userInput); | ||
printLine(); | ||
if (userInput.equals("list")) { | ||
Task.printList(); | ||
} else if(userInput.matches("mark \\d+")) { | ||
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. You may want to declare all the regex expressions being used as constants. This also allows you to just update the constant and reuse that at multiple places, without needing to update it at every place you declared it initially. |
||
String[] taskIndex = userInput.split(" "); | ||
int index = Integer.parseInt(taskIndex[1]); | ||
Task.markDone(index-1); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(" [X] " + Task.tasks[index-1]); | ||
} else if(userInput.matches("unmark \\d+")) { | ||
String[] taskIndex = userInput.split(" "); | ||
int index = Integer.parseInt(taskIndex[1]); | ||
Task.markUndone(index-1); | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
System.out.println(" [ ] " + Task.tasks[index-1]); | ||
} else { | ||
Task.addTask(userInput); | ||
} | ||
userInput = in.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. This code block can be abstracted to improve the code readability. Usually, methods should not be longer than 30 Lines of Code. |
||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
} |
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.
Advisable to have a uniform spacing strategy, to enhance code readability.