-
Notifications
You must be signed in to change notification settings - Fork 197
[limleyhooi] iP #227
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
base: master
Are you sure you want to change the base?
[limleyhooi] iP #227
Changes from 10 commits
817846f
c5fd455
50c81a9
4e9d824
340187b
b56022f
487f813
ea54e99
278b61f
e440954
073a202
6da1f44
6973f03
c1c2e94
59e4fd5
e87ecaa
d1b0245
17cf10a
6eec05d
65581d7
5151f5f
48fc7c4
18c5c52
169974a
ef36226
19ff875
2d33c75
db1c9b3
6651a07
1579be4
ef38112
16a4000
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 description; | ||
| protected String date; | ||
| public Deadline(String description, String date){ | ||
| super(description); | ||
| this.date = date; | ||
| } | ||
| @Override | ||
| public String toString(){ | ||
| return "[D]" + super.toString() + " (by: " + date + ")"; | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| public class Event extends Task{ | ||
| protected String description; | ||
| protected String time1; | ||
| protected String time2; | ||
| public Event(String description, String time1, String time2){ | ||
| super(description); | ||
| this.time1 = time1; | ||
| this.time2 = time2; | ||
| } | ||
| @Override | ||
| public String toString(){ | ||
| return "[E]" + super.toString() + " (from: " + time1 + " to: " + time2 + ")"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,144 @@ | ||||||||||||||||||||
| import java.util.Scanner ; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public class Rick { | ||||||||||||||||||||
| private static final String DIVIDER = " ____________________________________________________________"; | ||||||||||||||||||||
| private static void printDivider() { | ||||||||||||||||||||
| System.out.println(DIVIDER); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| public static void main(String[] args) { | ||||||||||||||||||||
| String logo = | ||||||||||||||||||||
| " ____ _ _ \n" + | ||||||||||||||||||||
| "| _ \\(_) ___| | __\n" + | ||||||||||||||||||||
| "| |_) | |/ __| |/ /\n" + | ||||||||||||||||||||
| "| _ <| | (__| < \n" + | ||||||||||||||||||||
| "|_| \\_\\_|\\___|_|\\_\\"; | ||||||||||||||||||||
| System.out.println("Hello from\n" + logo); | ||||||||||||||||||||
| System.out.println(""" | ||||||||||||||||||||
| Hello, I'm rick (´。• ᵕ •。`) | ||||||||||||||||||||
| What can I do for you? | ||||||||||||||||||||
| """); | ||||||||||||||||||||
| Scanner s = new Scanner(System.in); | ||||||||||||||||||||
| Task[] tasks = new Task[100]; //create an Task array called tasks that hold 100 Task elements; | ||||||||||||||||||||
|
||||||||||||||||||||
| int i = 0; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| while (true) { | ||||||||||||||||||||
| System.out.print(">"); | ||||||||||||||||||||
| String input = s.nextLine(); //enter string element; | ||||||||||||||||||||
| input = input.replaceAll("\\s","");//remove all spaces in user input. | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| if (input.startsWith("bye")) { | ||||||||||||||||||||
| System.out.println("bye bye! Hope to see you soon (づ ̄ ³ ̄)づ"); | ||||||||||||||||||||
| break; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (input.startsWith("list")){ | ||||||||||||||||||||
| if (i ==0) { | ||||||||||||||||||||
| System.out.println(" No tasks added (;ↀ⌓ↀ)"); //tasks array is empty | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| System.out.println("Here are the items in your list ᕦ(ò_óˇ)ᕤ :"); | ||||||||||||||||||||
| for (int j = 0; j < i; j++) { | ||||||||||||||||||||
| System.out.print(j + 1+"."); //iterate through tasks array; | ||||||||||||||||||||
| System.out.println(tasks[j]); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| continue; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if(input.startsWith("mark")){ | ||||||||||||||||||||
| int taskIndex = 0;//declare and initialise outside try-catch block; | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| taskIndex = Integer.parseInt(input.substring(4)) - 1; //finding the index to mark; | ||||||||||||||||||||
| if (taskIndex >= 0 && taskIndex < i) { | ||||||||||||||||||||
| tasks[taskIndex].markAsDone(); | ||||||||||||||||||||
| printDivider(); | ||||||||||||||||||||
| System.out.println(" Nicee! I've marked this task as done ᕕ( ᐛ )ᕗ :"); | ||||||||||||||||||||
| System.out.println(tasks[taskIndex]); | ||||||||||||||||||||
| printDivider(); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| System.out.println("Invalid task number!"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }catch(NumberFormatException e){ | ||||||||||||||||||||
| System.out.println("only a number after mark! O_o"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| continue; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if(input.startsWith("unmark")){ | ||||||||||||||||||||
| int taskIndex = 0; | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| taskIndex = Integer.parseInt(input.substring(6)) - 1; | ||||||||||||||||||||
| if (taskIndex >= 0 && taskIndex < i) { | ||||||||||||||||||||
| tasks[taskIndex].markAsUndone(); | ||||||||||||||||||||
| printDivider(); | ||||||||||||||||||||
| System.out.println(" Gotcha! I've unmarked this task (≧▽≦)"); | ||||||||||||||||||||
| System.out.println(tasks[taskIndex]); | ||||||||||||||||||||
| printDivider(); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| System.out.println("Invalid task number!"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }catch(NumberFormatException e){ | ||||||||||||||||||||
| System.out.println("only a number after unmark! o_O"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| continue; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if(input.startsWith("todo")){ | ||||||||||||||||||||
| input = input.substring(4); | ||||||||||||||||||||
| try{ | ||||||||||||||||||||
| if(input.isEmpty()){ | ||||||||||||||||||||
| throw new RickException(); | ||||||||||||||||||||
| }}catch(RickException e){ | ||||||||||||||||||||
|
||||||||||||||||||||
| try{ | |
| if(input.isEmpty()){ | |
| throw new RickException(); | |
| }}catch(RickException e){ | |
| try { | |
| if (input.isEmpty()) { | |
| throw new RickException(); | |
| } | |
| } catch (RickException e) { |
Consider following the coding standard as shown above to maintain consistency and readability throughout your code.
Outdated
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.
Variable names must be in camelCase
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| public class RickException extends Exception{ | ||
| //empty; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X | ||
| } | ||
|
|
||
| public void markAsDone(){ | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| public void markAsUndone(){ | ||
| this.isDone = false; | ||
| } | ||
| @Override | ||
| public String toString(){ | ||
| return "[" + getStatusIcon() +"] " + description; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| public class Todo extends Task{ | ||
| public Todo(String description){ | ||
| super(description); | ||
| } | ||
| @Override | ||
| public String toString(){ | ||
| return "[T]" + 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.
Consider using a more descriptive name such as startTime, endTime instead of time1 and time2.