-
Notifications
You must be signed in to change notification settings - Fork 590
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
[Nihirraa] ip #643
base: master
Are you sure you want to change the base?
[Nihirraa] ip #643
Changes from 8 commits
68c58c1
03523ec
81a9c53
4853d37
d46d608
7408eb1
71fd7e2
7f93304
9148f8e
87fd4a7
0aba9e7
aa2cb29
31d79ce
9c7333f
5d2a974
68cc04a
b1dbb02
151467e
64d2b58
623b278
bd882b8
ef15ad5
1b4e91b
451b292
d12aa50
ec5dd68
d19ade8
31bc0f0
9b22e2a
480ce49
11f70a2
94901c4
8c98153
6f6d6b3
bb1c609
ccf9cc0
1047d4c
b0c08d9
f1debb3
e37743b
61cc4b5
d82883b
45aa026
7a0d3f1
5295065
04780ef
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Duke User Guide | ||
# Espresso User Guide | ||
|
||
// Update the title above to match the actual product name | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
public class Espresso { | ||
private ArrayList<Task> tasks ; | ||
private int count; | ||
|
||
public Espresso() { | ||
tasks = new ArrayList<>(); | ||
count = 0; | ||
} | ||
|
||
void addToList(String str) { | ||
Task task = null; | ||
try { | ||
if (str.startsWith("todo")) { | ||
String status = str.substring(4).trim(); | ||
if (status.isEmpty()) | ||
throw new IllegalArgumentException("Description of todo task is required"); | ||
task = new todoTask(status); | ||
} else if (str.startsWith("deadline")) { | ||
String split[] = str.substring(8).split(" /by"); | ||
String status = split[0].trim(); | ||
if (status.isEmpty()) | ||
throw new IllegalArgumentException("Description of deadline task is required"); | ||
task = new deadlineTask(status, split[1].trim()); | ||
} else if (str.startsWith("event")) { | ||
String split1[] = str.substring(5).split(" /from "); | ||
String status = split1[0].trim(); | ||
if (status.isEmpty()) | ||
throw new IllegalArgumentException("Description of event task is required"); | ||
String split2[] = split1[1].split(" /to "); | ||
task = new eventTask(status, split2[0].trim(), split2[1].trim()); | ||
} else { | ||
throw new IllegalArgumentException("Random Input! I don't know what that means :("); | ||
} | ||
tasks.add(task); | ||
System.out.println("____________________________________________________________"); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + task); | ||
if (count == 0) | ||
System.out.println("Now you have " + (count + 1) + " task in the list."); | ||
else | ||
System.out.println("Now you have " + (count + 1) + " tasks in the list."); | ||
System.out.println("____________________________________________________________"); | ||
count++; | ||
} | ||
catch (IllegalArgumentException e) { | ||
System.out.println("____________________________________________________________"); | ||
System.out.println("Oops! " + e.getMessage()); | ||
System.out.println("____________________________________________________________"); | ||
} | ||
} | ||
|
||
void deleteTask(int position) { | ||
System.out.println("____________________________________________________________"); | ||
Task rem = tasks.remove(position); | ||
count--; | ||
System.out.println("Noted. I've removed this task:"); | ||
System.out.println(" " + rem); | ||
if (count == 1) | ||
System.out.println("Now you have " + count + " task in the list."); | ||
else | ||
System.out.println("Now you have " + count + " tasks in the list."); | ||
System.out.println("_________________________________________"); | ||
} | ||
|
||
void printList() { | ||
System.out.println("____________________________________________________________"); | ||
for (int i = 0; i < count; i++) { | ||
int num = i + 1; | ||
System.out.println(num + ". " + tasks.get(i)); | ||
} | ||
System.out.println("____________________________________________________________"); | ||
} | ||
|
||
void process() { | ||
System.out.println("_________________________________________"); | ||
System.out.println("Hello! I'm Espresso"); | ||
System.out.println("What can I do for you?"); | ||
System.out.println("_________________________________________"); | ||
Scanner sc = new Scanner(System.in); | ||
String str; | ||
while (true) { | ||
str = sc.nextLine(); | ||
|
||
if (str.equals("bye")) { | ||
System.out.println("____________________________________________________________"); | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
System.out.println("____________________________________________________________"); | ||
break; | ||
} else if (str.startsWith("mark ")) { | ||
String extractNum = str.substring(str.indexOf(' ') + 1).trim(); | ||
int pos = Integer.valueOf(extractNum); | ||
markTask(pos - 1); | ||
} else if (str.startsWith("unmark ")) { | ||
String extractNum = str.substring(str.indexOf(' ') + 1).trim(); | ||
int pos = Integer.valueOf(extractNum); | ||
unmarkTask(pos - 1); | ||
}else if (str.equals("list")) { | ||
printList(); | ||
} else if (str.startsWith("delete ")) { | ||
String extractNum = str.substring(str.indexOf(' ') + 1).trim(); | ||
int pos = Integer.valueOf(extractNum); | ||
deleteTask(pos - 1); | ||
} | ||
else { | ||
addToList(str); | ||
} | ||
} | ||
sc.close(); | ||
} | ||
void markTask(int position) { | ||
System.out.println("_________________________________________"); | ||
if (position >= 0 && position < count) { | ||
tasks.get(position).mark(); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(" " + tasks.get(position)); | ||
System.out.println("_________________________________________"); | ||
} else { | ||
System.out.println("Invalid task number."); | ||
} | ||
} | ||
|
||
private void unmarkTask(int position) { | ||
System.out.println("_________________________________________"); | ||
if (position >= 0 && position < count) { | ||
tasks.get(position).unmark(); | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
System.out.println(" " + tasks.get(position)); | ||
System.out.println("_________________________________________"); | ||
} else { | ||
System.out.println("Invalid task number."); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
Espresso esp = new Espresso(); | ||
esp.process(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
public class Task { | ||
private String status; | ||
private boolean isDone; | ||
|
||
public Task(String status) { | ||
this.status = status; | ||
this.isDone = false; | ||
} | ||
|
||
public void mark() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmark() { | ||
this.isDone = false; | ||
} | ||
|
||
public String getIcon() { | ||
return (isDone ? "[X]" : "[ ]"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getIcon() + " " + status; | ||
} | ||
} | ||
|
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 rename your class to be capitalised at the first letter. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class deadlineTask extends Task { | ||
private String dl; | ||
|
||
deadlineTask(String status, String dl) { | ||
super(status); | ||
this.dl = dl; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String icon = "[D]"; | ||
return icon + super.toString() + " (by: " + dl + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||
public class eventTask extends Task{ | ||||||
private String starts,ends; | ||||||
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 put a whitespace after the comma.
Suggested change
|
||||||
|
||||||
eventTask(String status, String starts, String ends){ | ||||||
super(status); | ||||||
this.starts = starts; | ||||||
this.ends = ends; | ||||||
} | ||||||
@Override | ||||||
public String toString() { | ||||||
String icon = "[E]"; | ||||||
return icon + super.toString() + " (from: " + starts + " to: " + ends + ")"; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class todoTask extends Task{ | ||
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. class name should start with capital letter |
||
public todoTask(String status) { | ||
super(status); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String icon = "[T]"; | ||
return icon + super.toString(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,40 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
_________________________________________ | ||
Hello! I'm Espresso | ||
What can I do for you? | ||
_________________________________________ | ||
____________________________________________________________ | ||
Got it. I've added this task: | ||
[T][ ] read book | ||
Now you have 1 task in the list. | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Got it. I've added this task: | ||
[D][ ] return book (by: Sunday) | ||
Now you have 2 tasks in the list. | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Got it. I've added this task: | ||
[E][ ] project meeting (from: Mon 2pm to: 4pm) | ||
Now you have 3 tasks in the list. | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
1. [T][ ] read book | ||
2. [D][ ] return book (by: Sunday) | ||
3. [E][ ] project meeting (from: Mon 2pm to: 4pm) | ||
____________________________________________________________ | ||
_________________________________________ | ||
Nice! I've marked this task as done: | ||
[T][X] read book | ||
_________________________________________ | ||
____________________________________________________________ | ||
1. [T][X] read book | ||
2. [D][ ] return book (by: Sunday) | ||
3. [E][ ] project meeting (from: Mon 2pm to: 4pm) | ||
____________________________________________________________ | ||
_________________________________________ | ||
OK, I've marked this task as not done yet: | ||
[T][ ] read book | ||
_________________________________________ | ||
____________________________________________________________ | ||
Bye. Hope to see you again soon! | ||
____________________________________________________________ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
todo read book | ||
deadline return book /by Sunday | ||
event project meeting /from Mon 2pm /to 4pm | ||
list | ||
mark 1 | ||
list | ||
unmark 1 | ||
bye |
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.
You may change the if-statement indentation to indentation to once (4 spaces) instead of twice.