-
Notifications
You must be signed in to change notification settings - Fork 228
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
[Andrea Tan] iP #263
base: master
Are you sure you want to change the base?
[Andrea Tan] iP #263
Changes from 1 commit
af7e8f9
c621220
b3a5323
25b1d6b
dd45d1b
26418a3
0a0fc47
18b425d
a7089c6
75632ce
2061878
b785eec
5ea5f47
1f42308
8b0510b
e7cb203
3038258
c475678
b5e8f0f
a61b6df
62293f2
081fe4e
c9172b6
1abb403
ae13b46
382cb20
e6d3f36
be967e3
ddd5d12
b7d0bbe
7e15137
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
import java.lang.Throwable; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
|
@@ -21,38 +20,50 @@ public static void main(String[] args) { | |
while (!input.equals("bye")) { | ||
Task task; | ||
try { | ||
if (input.equals("list")) { | ||
displayList(list); | ||
System.out.println("\n"); | ||
} else if (input.contains("done")) { | ||
String[] doneCommand = input.split(" "); | ||
task = list.get(Integer.parseInt(doneCommand[1]) - 1); | ||
System.out.println("Good job! I've marked this task as done:\n " + | ||
task.markDone() + | ||
"\n"); | ||
} else if (input.contains("todo") || | ||
input.contains("deadline") || | ||
input.contains("event")) { | ||
if (input.equals("list")) { | ||
displayList(list); | ||
System.out.println("\n"); | ||
} else if (input.contains("done")) { | ||
String[] command = input.split(" "); | ||
task = list.get(Integer.parseInt(command[1]) - 1); | ||
System.out.println("Good job! I've marked this task as done:\n " + | ||
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 it's good that you kept the line of print statement short:> |
||
task.markDone() + | ||
"\n"); | ||
} else if (input.contains("delete")) { | ||
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. do you think maybe switch statements could be used to make the code look more concise? |
||
String[] command = input.split(" "); | ||
int index = Integer.parseInt(command[1]) - 1; | ||
task = list.get(index); | ||
System.out.println("Alright, I've deleted this task:\n " + | ||
task + | ||
"\n"); | ||
list.remove(index); | ||
System.out.println("Now you have " + list.size() + | ||
" task(s) in the list. \n"); | ||
} else if (input.contains("todo") || | ||
input.contains("deadline") || | ||
input.contains("event")) { | ||
|
||
if (input.contains("todo")) { | ||
task = new ToDo(input); | ||
} else if (input.contains("deadline")) { | ||
task = new Deadline(input); | ||
} else { | ||
task = new Event(input); | ||
} | ||
list.add(task); | ||
System.out.println("I'll take note! \n added: " + | ||
task + "\nNow you have " + list.size() + | ||
" task(s) in the list. \n"); | ||
if (input.contains("todo")) { | ||
task = new ToDo(input); | ||
} else if (input.contains("deadline")) { | ||
task = new Deadline(input); | ||
} else { | ||
task = new Event(input); | ||
} | ||
list.add(task); | ||
System.out.println("Alright! I've added this task: \n " + | ||
task + "\nNow you have " + list.size() + | ||
" task(s) in the list. \n"); | ||
} else { | ||
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 it is great that you implemented Duke Exceptions early! |
||
throw new DukeInvalidCommandException(); | ||
} | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
input = sc.nextLine(); | ||
} catch (IndexOutOfBoundsException e) { | ||
System.out.println("Oh no! This task does not exist. D:" ); | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
input = sc.nextLine(); | ||
} | ||
|
||
sc.close(); | ||
System.out.println("Bye! Stay on task!"); | ||
|
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 some java docs will be useful to make the user understand the code better!