-
Notifications
You must be signed in to change notification settings - Fork 228
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
[Kuek Yan Ling] iP #248
base: master
Are you sure you want to change the base?
[Kuek Yan Ling] iP #248
Changes from 10 commits
3b19ba1
a75fcee
77ee7e3
27ef333
cecd097
cd80752
6c6269a
96e15e5
76ba712
6597495
cfcf682
e59f9f4
5fcc0a6
9a16853
89416ab
dbb3271
e60caaa
0b06a57
b2ed9a0
628dd4f
e0eb53a
96fe041
3860020
1213091
47369e7
38eb8b5
7390e40
cd44e0f
573bb90
177e775
17ca5e2
a70beff
699f6cc
1e9c795
ff944f3
189ae2f
d7976a0
5c8e8f0
51a933e
2b78ce8
9b21785
67d669d
fc9f60a
ec49759
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,15 @@ | ||
public class DeadlineTask extends Task { | ||
|
||
protected String deadline; | ||
|
||
public DeadlineTask(String description, String deadlline) { | ||
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 there is a typo for a variable name for deadline rather than deadlline. 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 there can be Javadoc comments to tell readers how this method works. |
||
super(description); | ||
this.deadline = deadlline; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + "[" + getStatusIcon() + "] " + this.description | ||
+ " (by: " + this.deadline + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,189 @@ | ||
import java.util.*; | ||
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 imported classes should be listed explicitly? (: 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. importing tasks individually can be clearer. |
||
|
||
public class Duke { | ||
|
||
static void 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. Perhaps having a method name that briefly describes what it does would be clearer. 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 clearer if this method name starts with a verb? |
||
System.out.println("Hello! I'm Duke\n" + "What can I do for you?"); | ||
|
||
Scanner sc = new Scanner(System.in); | ||
String input = sc.nextLine(); | ||
|
||
while (!input.equals("bye")) { | ||
System.out.println(input); | ||
input = sc.nextLine(); | ||
} | ||
|
||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
|
||
|
||
static void level2() { | ||
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 the method names could be more descriptive? In verb form? (: |
||
System.out.println("Hello! I'm Duke\n" + "What can I do for you?"); | ||
|
||
Scanner sc = new Scanner(System.in); | ||
String input = sc.nextLine(); | ||
|
||
List<String> lst = new ArrayList<>(); | ||
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 the parameter name can be something like commands? lst may sound a bit unclear to readers. |
||
|
||
while (!input.equals("bye")) { | ||
if (!input.equals("list")) { | ||
lst.add(input); | ||
System.out.println("added: " + input); | ||
} else { | ||
for (int i = 1; i <= lst.size(); i++) { | ||
System.out.println(i + ". " + lst.get(i-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. Perhaps there should be whitespace on the left and right of the "-" sign? (: 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. Not sure if I liked that the - does not have whitespace before and after it. |
||
} | ||
} | ||
input = sc.nextLine(); | ||
} | ||
|
||
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. Perhaps more javadoc comments for the methods? (: |
||
static void level3() { | ||
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 would personally an access modifier for my method to show whether it can be used outside the package or class. |
||
List<Task> lst = new ArrayList<>(); | ||
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 instead of lst, using tasks could be clearer to know what the list contains. |
||
lst.add(new Task("read book")); | ||
lst.add(new Task("return book")); | ||
lst.add(new Task("buy bread")); | ||
lst.get(0).markAsDone(); | ||
|
||
Scanner sc = new Scanner(System.in); | ||
String input = sc.nextLine(); | ||
String[] inputArray = input.split(" "); | ||
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 rather than inputArray, you can have a plural form of the input to show that it has multiple parts. |
||
|
||
while (true) { | ||
if (input.equals("list")) { | ||
System.out.println("Here are the tasks in your list:"); | ||
|
||
for (int i = 1; i <= lst.size(); i++) { | ||
System.out.println(i + "." + lst.get(i - 1)); | ||
} | ||
} else if (inputArray[0].equals("done")) { | ||
System.out.println("Nice! I've marked this task as done:"); | ||
lst.get(Integer.parseInt(inputArray[1]) - 1).markAsDone(); | ||
System.out.println(" " + lst.get(Integer.parseInt(inputArray[1]) - 1)); | ||
} | ||
|
||
input = sc.nextLine(); | ||
inputArray = input.split(" "); | ||
} | ||
} | ||
|
||
static void level4() throws DukeException { | ||
List<Task> lst = new ArrayList<>(); | ||
lst.add(new ToDoTask("read book")); | ||
lst.add(new DeadlineTask("return book", "June 6th")); | ||
lst.add(new EventTask("project meeting", "Aug 6th 2-4pm")); | ||
lst.add(new ToDoTask("join sports club")); | ||
lst.get(0).markAsDone(); | ||
lst.get(3).markAsDone(); | ||
|
||
Scanner sc = new Scanner(System.in); | ||
String input; | ||
String[] inputArray; | ||
|
||
while (sc.hasNextLine()) { | ||
input = sc.nextLine(); | ||
inputArray = input.split(" "); | ||
if (inputArray[0].equals("list")) { | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int i = 1; i <= lst.size(); i++) { | ||
System.out.println(i + "." + lst.get(i - 1)); | ||
} | ||
} else if (inputArray[0].equals("todo") || inputArray[0].equals("deadline") || inputArray[0].equals("event")) { //adding a task | ||
Task task = new Task(""); | ||
String[] inputArr1; | ||
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 extracting all the code that deals with different types of tasks could make your code clearer. |
||
String[] inputArr2; | ||
if (inputArray[0].equals("todo")) { | ||
if (inputArray.length == 1) { | ||
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty."); | ||
} | ||
inputArr1 = input.split("todo "); | ||
task = new ToDoTask(inputArr1[1]); | ||
} else if (inputArray[0].equals("deadline")) { | ||
if (inputArray.length == 1) { | ||
throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty."); | ||
} | ||
inputArr1 = input.split("deadline "); | ||
inputArr2 = inputArr1[1].split(" /by "); | ||
task = new DeadlineTask(inputArr2[0], inputArr2[1]); | ||
} else if (inputArray[0].equals("event")) { | ||
if (inputArray.length == 1) { | ||
throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty."); | ||
} | ||
inputArr1 = input.split("event "); | ||
inputArr2 = inputArr1[1].split(" /at "); | ||
task = new EventTask(inputArr2[0], inputArr2[1]); | ||
} | ||
lst.add(task); | ||
System.out.println("Got it. I've added this task: "); | ||
System.out.println(" " + task); | ||
System.out.println("Now you have " + lst.size() + " tasks in the list."); | ||
} else { | ||
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
static void level6() throws DukeException { | ||
List<Task> lst = new ArrayList<>(); | ||
lst.add(new ToDoTask("read book")); | ||
lst.add(new DeadlineTask("return book", "June 6th")); | ||
lst.add(new EventTask("project meeting", "Aug 6th 2-4pm")); | ||
lst.add(new ToDoTask("join sports club")); | ||
lst.add(new ToDoTask("borrow book")); | ||
lst.get(0).markAsDone(); | ||
lst.get(1).markAsDone(); | ||
lst.get(3).markAsDone(); | ||
|
||
Scanner sc = new Scanner(System.in); | ||
String input; | ||
String[] inputArray; | ||
|
||
while (sc.hasNextLine()) { | ||
input = sc.nextLine(); | ||
inputArray = input.split(" "); | ||
if (inputArray[0].equals("list")) { | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int i = 1; i <= lst.size(); i++) { | ||
System.out.println(i + "." + lst.get(i - 1)); | ||
} | ||
} else if (inputArray[0].equals("delete")) { //deleting a task | ||
if (inputArray.length == 1) { | ||
throw new DukeException("☹ OOPS!!! The task number has not been specified."); | ||
} else if (Integer.parseInt(inputArray[1]) > lst.size()) { | ||
throw new DukeException("☹ OOPS!!! This task number does not exist."); | ||
} | ||
|
||
System.out.println("Noted. I've removed this task:"); | ||
System.out.println(" " + lst.get(Integer.parseInt(inputArray[1]) - 1)); | ||
lst.remove(Integer.parseInt(inputArray[1]) - 1); | ||
System.out.println("Now you have " + lst.size() + " tasks in the list."); | ||
} | ||
} | ||
} | ||
|
||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
try { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
level6(); | ||
} catch (DukeException e) { | ||
System.out.println(e); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class DukeException extends Exception { | ||
|
||
DukeException(String msg) { | ||
super(msg); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class EventTask extends Task { | ||
|
||
protected String eventDate; | ||
|
||
public EventTask(String description, String eventDate) { | ||
super(description); | ||
this.eventDate = eventDate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + "[" + getStatusIcon() + "] " + this.description | ||
+ " (at: " + this.eventDate + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class Task { | ||
protected String description; | ||
protected 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 the name of this boolean, clearly tells me what it does. |
||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); //return tick or X symbols | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public String toString() { | ||
return "[" + getStatusIcon() + "] " + this.description; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public enum TaskTypes { | ||
TODO, DEADLINE, EVENT; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ToDoTask extends Task { | ||
|
||
public ToDoTask(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + "[" + getStatusIcon() + "] " + this.description; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
todo borrow book | ||
list | ||
deadline return book /by Sunday | ||
event project meeting /at Mon 2-4pm |
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.
Maybe you can consider putting classes into packages.