-
Notifications
You must be signed in to change notification settings - Fork 361
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
[Saha9616] iP #371
base: master
Are you sure you want to change the base?
[Saha9616] iP #371
Changes from 7 commits
556af3f
4f0dba8
81316d4
ca436b5
4afa0d0
23ceeaf
8b74572
280dd89
347743d
a23db4d
182c772
a387450
b15e2c2
ea355bb
1ca4046
29fd30c
a106830
449811f
eb60dac
d567558
d7ad960
7d5efaa
0eaeda1
6556b62
7c67085
c379f16
cac14c4
8e363ce
5476dcc
e990d89
9a72ac2
dcd13e3
79a2770
e2dcd93
579e5b8
9400f1e
2598518
3bb90aa
96d046d
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,24 @@ | ||
public class Deadline extends Task{ | ||
|
||
|
||
public Deadline(String str1) { | ||
super(str1); | ||
} | ||
|
||
String[] mainSplit = super.task_name.split(" ", 2); | ||
String name = mainSplit[1]; // gives "return book /by Sunday" | ||
String[] StrList = name.split(" /by ", 2); //gives ["return book", "Sunday"] | ||
String nameMain = StrList[0]; //gives "return book" | ||
String dl = "(by: " + StrList[1] + ")"; //gives "by: Sunday" | ||
|
||
|
||
@Override | ||
public String toString() { | ||
if(super.status == true) { | ||
return "[D][X] " + nameMain + " " + dl; | ||
} | ||
else { | ||
return "[D][ ] " + nameMain + " " + dl; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,93 @@ | ||
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. import.* syntax is discouraged |
||
import java.util.ArrayList; | ||
public class Duke { | ||
public static Scanner sc = new Scanner(System.in); | ||
public static ArrayList<Task> lst = new ArrayList<Task>(); | ||
public static void add_to_list(String str) throws InvalidCommandException, NoDescriptionException{ | ||
|
||
if((str.split(" ", 2).length == 1)) { | ||
throw new NoDescriptionException(); | ||
} | ||
else if((str.split(" ", 2)[0]).equals("todo")) { | ||
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. Maybe you should consider using |
||
|
||
lst.add(new Todo(str)); | ||
} | ||
else if((str.split(" ", 2)[0]).equals("deadline")) { | ||
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. The |
||
lst.add(new Deadline(str)); | ||
} | ||
else if((str.split(" ", 2)[0]).equals("event")) { | ||
lst.add(new Event(str)); | ||
} | ||
else { | ||
throw new InvalidCommandException(); | ||
} | ||
int size = lst.size(); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + lst.get(size-1).toString()); | ||
System.out.println("Now you have " + size + " tasks in the list"); | ||
} | ||
|
||
public static void print_list() { | ||
for(int i = 0; i < lst.size(); i++) { | ||
|
||
System.out.println((i+1) + ". " + lst.get(i).toString()); | ||
} | ||
} | ||
|
||
public static void mark(Task tsk) { | ||
tsk.toggleTrue(); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(tsk.toString()); | ||
} | ||
|
||
public static void unmark(Task tsk) { | ||
tsk.toggleFalse(); | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
System.out.println(tsk.toString()); | ||
} | ||
public static void reply() { | ||
String str = sc.nextLine(); | ||
if(str.equals("bye")) { | ||
System.out.println("Bye mortal, I will get back to destroying" + | ||
" galaxies"); | ||
} | ||
else if(str.equals("list")) { | ||
print_list(); | ||
reply(); | ||
} | ||
else if((str.split(" ", 2)[0]).equals("mark")) { | ||
mark(lst.get(Integer.parseInt((str.split(" ", 2)[1])) - 1)); | ||
reply(); | ||
} | ||
else if((str.split(" ", 2)[0]).equals("unmark")) { | ||
unmark(lst.get(Integer.parseInt((str.split(" ", 2)[1])) - 1)); | ||
reply(); | ||
} | ||
else if((str.split(" ", 2)[0]).equals("delete")) { | ||
System.out.println("Noted. I've removed this task:"); | ||
System.out.println(" " + lst.get(Integer.parseInt((str.split(" ", 2)[1])) - 1).toString()); | ||
lst.remove(Integer.parseInt((str.split(" ", 2)[1])) - 1); | ||
System.out.println("Now you have " + lst.size() + " tasks in the list."); | ||
reply(); | ||
} | ||
else { | ||
try { | ||
add_to_list(str); | ||
} | ||
catch(InvalidCommandException e) { | ||
System.out.println("the command is invalid"); | ||
} | ||
catch(NoDescriptionException e) { | ||
System.out.println("the task needs to have a description"); | ||
} | ||
reply(); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
} | ||
} | ||
String welcome_msg = "Hello my name is Thanos, my hobbies are helping people maintain their schedule and " + | ||
"destroying galaxies."; | ||
System.out.println(welcome_msg); | ||
reply(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class DukeException extends Exception { | ||
private String message; | ||
public DukeException() { | ||
this.message = "bogus"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
public class Event extends Task { | ||
|
||
public Event(String str1) { | ||
super(str1); | ||
} | ||
|
||
String[] mainSplit = super.task_name.split(" ", 2); //original : "event project meeting /from Mon 2pm /to 4pm" | ||
String name = mainSplit[1]; // gives "project meeting /from Mon 2pm /to 4pm" | ||
String[] StrList1 = name.split(" /from ", 2); //gives ["project meeting","Mon 2pm /to 4pm"] | ||
String nameMain = StrList1[0]; //gives "project meeting" | ||
String[] StrList2 = StrList1[1].split(" /to ", 2); //gives ["Mon 2pm", "to 4pm"] | ||
String frm = StrList2[0]; //gives "Mon 2pm" | ||
String to = StrList2[1]; //gives "to 4pm" | ||
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 proper naming of variables can help to reduce the number of comments. Maybe consider |
||
String finalTime = "from " + frm + " to " + to; | ||
|
||
|
||
@Override | ||
public String toString() { | ||
if(super.status == 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. There should be a space between |
||
return "[E][X] " + nameMain + " " + finalTime; | ||
} | ||
else { | ||
return "[E][ ] " + nameMain + " " + finalTime; | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class InvalidCommandException extends DukeException{ | ||
public InvalidCommandException() { | ||
super(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class NoDescriptionException extends DukeException{ | ||
public NoDescriptionException() { | ||
super(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public abstract class Task { | ||
|
||
public String task_name; | ||
public boolean status; | ||
public Task(String str) { | ||
task_name = str; | ||
status = false; | ||
} | ||
|
||
public void toggleTrue() { | ||
status = true; | ||
} | ||
|
||
public void toggleFalse() { | ||
status = false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class Todo extends Task { | ||
|
||
public Todo(String str1) { | ||
super(str1); | ||
} | ||
String[] mainSplit = super.task_name.split(" ", 2); | ||
String name = mainSplit[1]; | ||
|
||
|
||
@Override | ||
public String toString() { | ||
if(super.status == true) { | ||
return "[T][X] " + name; | ||
} | ||
else { | ||
return "[T][ ] " + name; | ||
} | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
Hello my name is Thanos, my hobbies are helping people maintain their schedule and destroying galaxies. | ||
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][ ] cry about my cap (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 | ||
Nice! I've marked this task as done: | ||
[D][X] cry about my cap (by: Sunday) | ||
Nice! I've marked this task as done: | ||
[T][X] borrow book | ||
Got it. I've added this task: | ||
[T][ ] eat popcorn | ||
Now you have 4 tasks in the list | ||
1. [T][X] borrow book | ||
2. [D][X] cry about my cap (by: Sunday) | ||
3. [E][ ] project meeting from Mon 2pm to 4pm\ | ||
4. [T][ ] eat popcorn | ||
OK, I've marked this task as not done yet: | ||
[T][ ] borrow book | ||
Bye mortal, I will get back to destroying galaxies |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
todo borrow book | ||
deadline cry about my cap /by Sunday | ||
event project meeting /from Mon 2pm /to 4pm\ | ||
mark 2 | ||
mark 1 | ||
todo eat popcorn | ||
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.
Your files are missing package declarations
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.
Should the classes be in a package?