-
Notifications
You must be signed in to change notification settings - Fork 461
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
[Singh Abdullah Alexander] iP #519
base: master
Are you sure you want to change the base?
Changes from 10 commits
556af3f
df365b5
1346cd5
35f557b
1427298
924806e
7a099dd
23228eb
79c8c7b
a9e73ff
c267e54
08cf255
917c4da
dafa0e1
ab17e07
ee3871e
2b04497
c453a9a
0770b6e
8e27eb5
d930758
ddbd5f6
36fb04e
b055c54
c225250
d2722ef
d88c342
a5e7b67
56ab4d6
dfc760d
59bf323
4da3212
fd0c357
692246c
4cfda08
2bfa59e
0567cc5
e386799
b668147
c46ee09
0f7a2fe
1c5c16d
9c75ccf
bbf40fc
19c3253
ce78d08
01a6f58
ddd0c10
a0be07b
81eec33
9de9aa0
723befa
59e259f
2bf9003
36401c4
8619248
4562947
ee1e14a
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,103 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
|
||
public class Chacha { | ||
public static void main(String[] args) { | ||
System.out.println("Hello! I'm Chacha\n" + "What can I do for you?"); | ||
Scanner input = new Scanner(System.in); | ||
String s = input.nextLine(); | ||
ArrayList<Task> taskList = new ArrayList<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. Good that the variable names are in camel case 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. Can consider making taskList a private static final field in the class |
||
while (!s.equals("bye")) { | ||
if (s.equals("list")) { | ||
for (int i = 0; i < taskList.size();i++) { | ||
Task t = taskList.get(i); | ||
System.out.println(i + 1 + | ||
"." + | ||
t.toString()); | ||
} | ||
|
||
} else if (s.contains("unmark")) { | ||
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. Can consider using s.startsWith function to check if the task type is indeed the first input |
||
|
||
String[] split = s.split("\\s+"); | ||
Task task = taskList.get(Integer.valueOf(split[1]) - 1); | ||
task.unmarkAsDone(); | ||
System.out.println("OK, I've marked this task as not done yet:\n" + task.toString()); | ||
|
||
} else if (s.contains("mark")) { | ||
String[] split = s.split("\\s+"); | ||
Task task = taskList.get(Integer.valueOf(split[1]) - 1); | ||
task.markAsDone(); | ||
System.out.println("Nice! I've marked this task as done:\n" + task.toString()); | ||
|
||
} else if (s.contains("delete")) { | ||
String[] split = s.split("\\s+"); | ||
Task task = taskList.get(Integer.valueOf(split[1]) - 1); | ||
System.out.println("Noted. I've removed this task:"); | ||
System.out.println(task.toString()); | ||
taskList.remove(Integer.valueOf(split[1]) - 1); | ||
System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
|
||
} else if (s.contains("deadline")) { | ||
try { | ||
String date = s.substring(s.indexOf("/by ") + 4); | ||
date.trim(); | ||
String description = s.substring(0,s.indexOf("/")); | ||
description = description.substring(s.indexOf("deadline ") + 9); | ||
description.trim(); | ||
Deadline deadline = new Deadline(description, date); | ||
taskList.add(deadline); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(deadline.toString()); | ||
System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
} catch(Exception e) { | ||
System.out.println("OOPS!!! The description of a deadline cannot be empty."); | ||
} | ||
} else if (s.contains("todo")) { | ||
try { | ||
String description = s.substring(s.indexOf("todo ") + 5); | ||
System.out.println("heree"); | ||
description.trim(); | ||
Todo todo = new Todo(description); | ||
taskList.add(todo); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(todo.toString()); | ||
System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
} catch(Exception e) { | ||
System.out.println("OOPS!!! The description of a todo cannot be empty."); | ||
} | ||
|
||
} else if (s.contains("event")) { | ||
try { | ||
String range = s.substring(s.indexOf("/at ") + 4); | ||
range.trim(); | ||
String description = s.substring(0,s.indexOf("/")); | ||
description = description.substring(s.indexOf("event ") + 6); | ||
description.trim(); | ||
Event event = new Event(description, range); | ||
taskList.add(event); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(event.toString()); | ||
System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
} catch(Exception e) { | ||
System.out.println("OOPS!!! The description of a event cannot be empty."); | ||
} | ||
} else { | ||
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
} | ||
s = input.nextLine(); | ||
} | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
input.close(); | ||
} | ||
|
||
private static void loadData(String filePath) throws FileNotFoundException { | ||
File f = new File(filePath); // create a File for the given file path | ||
Scanner s = new Scanner(f); // create a Scanner using the File as the source | ||
while (s.hasNext()) { | ||
//load task objects into array | ||
System.out.println(s.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. Overall code looks clean and should have no problem finishing up the ip |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import java.text.DateFormat; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class Deadline extends Task { | ||
private String description; | ||
private LocalDate date; | ||
private 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. Good naming of booleans:) |
||
private String type; | ||
|
||
public Deadline(String description, String date) { | ||
this.description = description; | ||
this.date = LocalDate.parse(date); | ||
this.type = "D"; | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmarkAsDone() { | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getDate() { | ||
String formattedDate = date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); | ||
return formattedDate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + type + "]" + "[" + getStatusIcon() + "] " + description + "(by: " + getDate() + ")"; | ||
} | ||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import java.text.DateFormat; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class Event extends Task { | ||
private String description; | ||
private LocalDate range; | ||
private boolean isDone; | ||
private String type; | ||
|
||
public Event(String description, String range) { | ||
this.description = description; | ||
this.range = LocalDate.parse(range); | ||
this.type = "E"; | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmarkAsDone() { | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getDate() { | ||
String formattedDate = range.format(DateTimeFormatter.ofPattern("MMM d yyyy")); | ||
return formattedDate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + type + "]" + "[" + getStatusIcon() + "] " + description + "(at: " + getDate() + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class Task { | ||
private String description; | ||
private boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public Task() { | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmarkAsDone() { | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
public class Todo extends Task { | ||
private String description; | ||
private boolean isDone; | ||
private String type; | ||
|
||
public Todo(String description) { | ||
this.description = description; | ||
this.type = "T"; | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmarkAsDone() { | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + type + "]" + "[" + getStatusIcon() + "] " + description; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
Hello! I'm Chacha | ||
What can I do for you? | ||
Got it. I've added this task: | ||
[T][ ] borrow book | ||
Now you have 1 tasks 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 (at: Mon 2-4pm) | ||
Now you have 3 tasks in the list. | ||
Nice! I've marked this task as done: | ||
[D][X] return book (by: Sunday) | ||
1.[T][ ] borrow book | ||
2.[D][X] return book (by: Sunday) | ||
3.[E][ ] project meeting (at: Mon 2-4pm) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
todo borrow book | ||
deadline return book /by Sunday | ||
event project meeting /at Mon 2-4pm | ||
mark 2 | ||
list |
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 can name s differently? To a clearer variable