-
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
[Teh Kok Hoe] iP #309
base: master
Are you sure you want to change the base?
[Teh Kok Hoe] iP #309
Changes from 16 commits
db7b3b9
f5cc97c
3a03048
98dd74f
82e3f0b
666bf39
3e42bcc
2623e50
2f2eae3
c6c76f9
7253df2
cd2cec9
074b3d5
220ea0d
575afdb
53d3490
d355645
fb0bb08
613ba0f
7ab38ce
c5d5d5e
d418108
74b2b4d
0fe362e
70a8771
603ab96
80b2d81
4967046
5c83648
1536f41
1ac0efb
9ced633
d83efcc
1642bc7
dc491b3
f9dfa90
4fdd0ad
f429a7d
5bee490
2b64ac0
7145edb
8d43a6c
b94ab8b
4a75f69
4e8656a
f70a410
d2fa202
d172734
c78b885
86ccd94
1ec936f
79edc3b
32b47dc
1a2789b
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,13 @@ | ||
public class Deadline extends Task { | ||
private String by; | ||
|
||
public Deadline(String task, String by) { | ||
super(task); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,166 @@ | ||
import java.util.*; | ||
|
||
public class Duke { | ||
enum Command { | ||
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 to see you're using enums for this! Keep it up. |
||
BYE, | ||
LIST, | ||
MARK, | ||
UNMARK, | ||
TODO, | ||
DEADLINE, | ||
EVENT, | ||
DELETE | ||
; | ||
} | ||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println(" ____________________________________________________________"); | ||
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. Instead of using 4 spaces, you can consider using |
||
System.out.println(" Hello! I'm Duke"); | ||
System.out.println(" What can I do for you?"); | ||
System.out.println(" ____________________________________________________________"); | ||
boolean StillIn = 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. Use camelCase to name variables, and booleans should be of the form |
||
FastReader fr = new FastReader(); | ||
ArrayList<Task> list = new ArrayList<Task>(100); | ||
while(StillIn) { | ||
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 think you need to put spacing between the brackets and each |
||
String in = fr.nextLine(); | ||
String[] input = in.split(" ", 2); | ||
Command cmd = Command.valueOf(input[0].toUpperCase()); | ||
System.out.println(" ____________________________________________________________"); | ||
try { | ||
switch (cmd) { | ||
case BYE: | ||
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.
|
||
System.out.println(bye()); | ||
StillIn = false; | ||
break; | ||
|
||
case LIST: | ||
list(list); | ||
break; | ||
|
||
case MARK: | ||
if(input.length < 2) { | ||
throw new DukeException(" ☹ OOPS!!! I don't know what to mark"); | ||
} | ||
|
||
int numMark = Integer.parseInt(input[1]); | ||
|
||
if(numMark > list.size()) { | ||
throw new DukeException(" ☹ OOPS!!! I don't see your task"); | ||
} | ||
|
||
list.get(numMark - 1).setDone(); | ||
System.out.println(" Nice! I've marked this task as done:"); | ||
System.out.println(" " + list.get(numMark - 1)); | ||
break; | ||
|
||
case UNMARK: | ||
if(input.length < 2) { | ||
throw new DukeException(" ☹ OOPS!!! I don't know what to unmark"); | ||
} | ||
|
||
int numUnmark = Integer.parseInt(input[1]); | ||
|
||
if(numUnmark > list.size()) { | ||
throw new DukeException(" ☹ OOPS!!! I don't see your task"); | ||
} | ||
|
||
list.get(numUnmark - 1).setUndone(); | ||
System.out.println(" OK, I've marked this task as not done yet:"); | ||
System.out.println(" " + list.get(numUnmark - 1)); | ||
break; | ||
|
||
case TODO: | ||
if(input.length < 2) { | ||
throw new DukeException(" ☹ OOPS!!! The description of a todo cannot be empty"); | ||
} | ||
Task todo = new ToDo(input[1]); | ||
list.add(todo); | ||
System.out.println(" Got it. I've added this task:"); | ||
System.out.println(" " + todo); | ||
System.out.printf(" Now you have %d task(s) in the list\n", list.size()); | ||
break; | ||
|
||
case DEADLINE: | ||
if(input.length < 2) { | ||
throw new DukeException(" ☹ OOPS!!! The description of a deadline cannot be empty"); | ||
} | ||
String[] splitbydate = input[1].split(" /by "); | ||
if(splitbydate.length < 2) { | ||
throw new DukeException(" ☹ OOPS!!! I don't know when your task is due"); | ||
} | ||
String bydate = splitbydate[1]; | ||
Task deadline = new Deadline(splitbydate[0], bydate); | ||
list.add(deadline); | ||
System.out.println(" Got it. I've added this task:"); | ||
System.out.println(" " + deadline); | ||
System.out.printf(" Now you have %d task(s) in the list\n", list.size()); | ||
break; | ||
|
||
case EVENT: | ||
if(input.length < 2) { | ||
throw new DukeException(" ☹ OOPS!!! The description of an event cannot be empty"); | ||
} | ||
String[] splitatdate = input[1].split(" /at "); | ||
if(splitatdate.length < 2) { | ||
throw new DukeException(" ☹ OOPS!!! I don't know when your event happens"); | ||
} | ||
String atdate = splitatdate[1]; | ||
Task event = new Event(splitatdate[0], atdate); | ||
list.add(event); | ||
System.out.println(" Got it. I've added this task:"); | ||
System.out.println(" " + event); | ||
System.out.printf(" Now you have %d task(s) in the list\n", list.size()); | ||
break; | ||
|
||
case DELETE: | ||
if(input.length < 2) { | ||
throw new DukeException(" ☹ OOPS!!! I don't know what to delete"); | ||
} | ||
|
||
int removenum = Integer.parseInt(input[1]); | ||
|
||
if(removenum > list.size()) { | ||
throw new DukeException(" ☹ OOPS!!! I don't see your task"); | ||
} | ||
|
||
Task removedtask = list.remove(removenum - 1); | ||
System.out.println(" Noted. I've removed this task:"); | ||
System.out.println(" " + removedtask); | ||
System.out.printf(" Now you have %d task(s) in the list\n", list.size()); | ||
} | ||
} catch(DukeException err) { | ||
System.out.println(err.getMessage()); | ||
} catch(NumberFormatException err) { | ||
System.out.println(" ☹ OOPS!!! Task number given is not suitable"); | ||
} | ||
System.out.println(" ____________________________________________________________"); | ||
} | ||
} | ||
|
||
public static void list(ArrayList<Task> lst) { | ||
for(int i=0; i < lst.size(); i++) { | ||
if(i == 0) { | ||
System.out.println(" Here are the tasks in your list:"); | ||
} | ||
System.out.printf(" %d. %s\n", i + 1, lst.get(i)); | ||
} | ||
if(lst.size() == 0) { | ||
System.out.println(" There's nothing in your list"); | ||
} | ||
} | ||
|
||
public static String blah() { | ||
return " blah"; | ||
} | ||
|
||
public static String bye() { | ||
return " Bye. Hope to see you again soon!"; | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class DukeException extends Exception { | ||
public DukeException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Event extends Task { | ||
private String at; | ||
|
||
public Event(String task, String at) { | ||
super(task); | ||
this.at = at; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (at: " + at + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import java.io.BufferedReader; | ||
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 too sure if |
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Scanner; | ||
import java.util.StringTokenizer; | ||
|
||
public class FastReader { | ||
BufferedReader br; | ||
StringTokenizer st; | ||
|
||
public FastReader() | ||
{ | ||
br = new BufferedReader( | ||
new InputStreamReader(System.in)); | ||
} | ||
|
||
String next() | ||
{ | ||
while (st == null || !st.hasMoreElements()) { | ||
try { | ||
st = new StringTokenizer(br.readLine()); | ||
} | ||
catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return st.nextToken(); | ||
} | ||
|
||
int nextInt() { return Integer.parseInt(next()); } | ||
|
||
long nextLong() { return Long.parseLong(next()); } | ||
|
||
double nextDouble() | ||
{ | ||
return Double.parseDouble(next()); | ||
} | ||
|
||
String nextLine() | ||
{ | ||
String str = ""; | ||
try { | ||
str = br.readLine(); | ||
} | ||
catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return str; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
public class Task { | ||
private String task; | ||
private boolean done; | ||
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. According to the coding standards, this should be named |
||
|
||
public Task() { | ||
this.done = false; | ||
} | ||
|
||
public Task(String task) { | ||
this.task = task; | ||
this.done = false; | ||
} | ||
|
||
public String getTask() { | ||
return task; | ||
} | ||
|
||
public void setDone() { | ||
this.done = true; | ||
} | ||
|
||
public void setUndone() { | ||
this.done = false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return task.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if(other instanceof Task){ | ||
Task toCompare = (Task) other; | ||
return this.task.equals(toCompare.getTask()); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String temp; | ||
if(this.done) { | ||
temp = "X"; | ||
} else { | ||
temp = " "; | ||
} | ||
return "[" + temp + "] " + this.task; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public class ToDo extends Task { | ||
public ToDo(String task) { | ||
super(task); | ||
} | ||
|
||
@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.
Two things here: