-
Notifications
You must be signed in to change notification settings - Fork 267
[Ria Khaitan] iP #328
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
base: master
Are you sure you want to change the base?
[Ria Khaitan] iP #328
Changes from 7 commits
d839859
151461d
47b8641
b17138e
9c7b04f
753720c
9b13c8d
83929b9
23ce597
6ed0f74
641333d
04c29b8
b1955ad
e290e05
08f9af6
0d9e8c2
7e9f3b7
7752dbf
2b8b28d
ce15d66
73df732
5cec4bd
9a52a54
e6d592a
e4b8c5a
2bda280
f0b93f4
34a78ab
a18e31b
1640332
8d134fe
2b126c7
48d87fc
9bae6a7
0583ae0
8281bb2
b3ed67a
31e1a12
d97ad83
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 |
|---|---|---|
|
|
@@ -15,3 +15,4 @@ bin/ | |
|
|
||
| /text-ui-test/ACTUAL.txt | ||
| text-ui-test/EXPECTED-UNIX.TXT | ||
| *.class | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,108 @@ | ||
| import exceptions.DukeExceptions; | ||
| import exceptions.DukeInvalidInput; | ||
| import exceptions.DukeInvalidTodo; | ||
|
|
||
| import java.util.Scanner; | ||
| import java.util.ArrayList; | ||
|
|
||
| public class Duke { | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| public static void lineOne() { | ||
| System.out.println("*************************************************************************"); | ||
| } | ||
|
|
||
| public static void lineTwo() { | ||
| System.out.println("|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|"); | ||
| } | ||
|
|
||
| public static String makeDesc(String[] text, int len) { | ||
|
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 a more intuitive variable name here? |
||
| String newText = ""; | ||
| for (int i = 1; i < len; i++) { | ||
| newText = newText + text[i] + " "; | ||
| } | ||
| return newText.trim(); | ||
| } | ||
|
|
||
| public static void main(String[] args) throws DukeExceptions { | ||
|
|
||
| Scanner sc = new Scanner(System.in); | ||
| int num = 0; | ||
| int counter = 0; | ||
| ArrayList<Task> lists = new ArrayList<Task>(); | ||
| lineOne(); | ||
| System.out.println("Hi! I'm Halloumi ^_^"); | ||
| System.out.println("What do you need help with today?"); | ||
| lineOne(); | ||
| do { | ||
| String text = sc.nextLine(); | ||
| String[] textSplitOne = text.split("/"); //by and at | ||
| String[] textSplit = textSplitOne[0].split(" "); | ||
| String fullDesc = makeDesc(textSplit, textSplit.length); | ||
| try { | ||
| switch (textSplit[0]) { | ||
|
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. For case clauses, there is no indentation |
||
| case "bye": | ||
| num = 1; | ||
| System.out.println("See you soon! Have a good day ^_^"); | ||
| lineOne(); | ||
| break; | ||
| case "list": | ||
| for (int i = 0; i < lists.size(); i++) { | ||
| System.out.println(i + 1 + ". " + lists.get(i)); | ||
| } | ||
| break; | ||
| case "mark": | ||
| lineOne(); | ||
| System.out.println("Good Job! ^_^"); | ||
| System.out.println("Task number " + textSplit[1] + " has been marked as done!"); | ||
| int tNum = Integer.parseInt(textSplit[1]); | ||
| lists.get(tNum - 1).done(); | ||
| System.out.println(lists.get(tNum - 1)); | ||
| lineOne(); | ||
| break; | ||
| case "unmark": | ||
| lineOne(); | ||
| System.out.println("I've unmarked task number " + textSplit[1]); | ||
| System.out.println("Complete it soon! ^_^"); | ||
| int tNo = Integer.parseInt(textSplit[1]); | ||
| lists.get(tNo - 1).undo(); | ||
| System.out.println(lists.get(tNo - 1)); | ||
| lineOne(); | ||
| break; | ||
| case "todo": | ||
| try { | ||
| if(fullDesc.equals(" ") || fullDesc.equals("")) { | ||
| throw new DukeInvalidTodo(); | ||
| } | ||
| } | ||
| catch(DukeInvalidTodo e) { | ||
| System.err.println(e.getMessage()); | ||
| continue; | ||
| } | ||
| System.out.println("New task added:"); | ||
| Task t = new ToDo(fullDesc); | ||
| lists.add(t); | ||
| System.out.println(t); | ||
| break; | ||
| case "event": | ||
| System.out.println("New task added:"); | ||
| Task t1 = new Event(fullDesc, textSplitOne[1]); | ||
| lists.add(t1); | ||
| System.out.println(t1); | ||
| break; | ||
| case "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. Logical units within a block should be separated by a line, perhaps a space after each case would be ideal! |
||
| System.out.println("New task added:"); | ||
| Task t2 = new Deadline(fullDesc, textSplitOne[1]); | ||
| lists.add(t2); | ||
| System.out.println(t2); | ||
| break; | ||
| default: | ||
| throw new DukeInvalidInput(); | ||
|
|
||
| } | ||
| } catch (DukeInvalidInput e) { | ||
| System.err.println(e.getMessage()); | ||
| } | ||
| } | ||
| while (num == 0) ; | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| public class Task { | ||
| String description; | ||
| boolean isDone; | ||
|
|
||
| public Task(String desc) { | ||
| description = desc; | ||
| isDone = false; | ||
| } | ||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X | ||
| } | ||
|
|
||
| public String toString() { | ||
| return String.format("[%s] %s", getStatusIcon(), description); | ||
| } | ||
|
|
||
| public void done() { | ||
| isDone = true; | ||
| } | ||
|
|
||
| public void undo() { | ||
| isDone = false; | ||
| } | ||
| } | ||
|
|
||
| class ToDo 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. I like how the code has been indented |
||
| public ToDo(String desc) { | ||
| super(desc); | ||
| } | ||
|
|
||
| public String toString() { | ||
| return "[T]" + super.toString(); | ||
| } | ||
| } | ||
|
|
||
| class Event extends Task { | ||
| String at; | ||
|
|
||
| public Event(String desc, String b) { | ||
| super(desc); | ||
| at = b; | ||
| } | ||
| public String toString() { | ||
| return "[E]" + super.toString() + " (: " + at + ")"; | ||
| } | ||
| } | ||
|
|
||
| class Deadline extends Task { | ||
| String by; | ||
|
|
||
| public Deadline(String desc, String b) { | ||
| super(desc); | ||
| by = b; | ||
| } | ||
| public String toString() { | ||
| return "[D]" + super.toString() + " (: " + by + ")"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package exceptions; | ||
|
|
||
| public class DukeExceptions extends Exception { | ||
| public DukeExceptions(String output) { | ||
| super(output); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package exceptions; | ||
|
|
||
| public class DukeInvalidInput extends DukeExceptions { | ||
| public DukeInvalidInput() { | ||
| super("ENTER A VALID INPUT! ^_^"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package exceptions; | ||
|
|
||
| public class DukeInvalidTodo extends DukeExceptions { | ||
| public DukeInvalidTodo() { | ||
| super("ENTER A DESCRIPTION! ^_^"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,24 @@ | ||
| Hello from | ||
| ____ _ | ||
| | _ \ _ _| | _____ | ||
| | | | | | | | |/ / _ \ | ||
| | |_| | |_| | < __/ | ||
| |____/ \__,_|_|\_\___| | ||
|
|
||
| ************************************************************************* | ||
| Hi! I'm Halloumi ^_^ | ||
| What do you need help with today? | ||
| ************************************************************************* | ||
| |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | ||
| New task added: | ||
| [T][ ] borrow book | ||
| You have 1 tasks in the list now! ^_^ | ||
| |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | ||
| |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | ||
| New task added: | ||
| [E][ ] wake up (: at 8am) | ||
| You have 2 tasks in the list now! ^_^ | ||
| |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | ||
| |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | ||
| New task added: | ||
| [D][ ] submit assignment (: by Sunday) | ||
| You have 3 tasks in the list now! ^_^ | ||
| |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | ||
| 1. [T][ ] borrow book | ||
| 2. [E][ ] wake up (: at 8am) | ||
| 3. [D][ ] submit assignment (: by Sunday) | ||
| See you soon! Have a good day ^_^ | ||
| ************************************************************************* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| todo borrow book | ||
| event wake up /at 8am | ||
| deadline submit assignment /by Sunday | ||
| list | ||
| 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.
Should the import statements be ordered differently?