-
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
[Jeremykhoo] iP #360
base: master
Are you sure you want to change the base?
[Jeremykhoo] iP #360
Changes from 6 commits
556af3f
11b5c57
acf0f45
f4b87a7
f416739
ab0a146
377d098
50f6250
8672b06
8caf430
bf2a6b8
16a25aa
ac27e67
5ec800b
3b6f151
6a80409
5cafe0a
a362945
eef2648
57f2ea8
4a42fa7
b242f82
0610e23
b1a8543
dff0749
0e229bd
2b3ac2f
8d5aa19
3afb857
46737fb
54dfb51
18ed672
04f09c3
02cf756
7e4cc29
ced7eda
61219b6
8515b69
7d65475
802b202
27015d1
7a87b02
6823422
3325650
006442d
94819eb
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,5 @@ bin/ | |
|
||
/text-ui-test/ACTUAL.TXT | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
*.class | ||
token |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Deadline extends Task { | ||
|
||
protected String by; | ||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + by + ")"; | ||
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 believe this file has extra level of indentations here weirdly. I notice the same issue occurring in other files too... |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,211 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Arrays; | ||
public class Duke { | ||
public static void main(String[] args) { | ||
private static ArrayList<Task> list; | ||
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. This is an interesting concept of ensuring only one instance of task list exists. Any reason it is designed this way? If new Duke was somehow initialised, the array list is 'resetted' base on how the constructor is written now |
||
|
||
public Duke() { | ||
this.list = new ArrayList<>(); | ||
} | ||
|
||
private static void line(int l) { | ||
System.out.print('\n'); | ||
for (int i =0; i < l + 15; i++) { | ||
System.out.print('_'); | ||
} | ||
System.out.print('\n'); | ||
} | ||
|
||
private static void showList() { | ||
int j = 0; | ||
for (Task i: list) { | ||
j++; | ||
System.out.println(String.valueOf(j) + ". " + i); | ||
} | ||
} | ||
|
||
private static void markTask(int i, boolean b) { | ||
int index = i - 1; | ||
list.get(index).markTask(b); | ||
System.out.println("Marked/Unmarked the task, task is in the state:"); | ||
System.out.print(" " + list.get(index)); | ||
} | ||
|
||
private static void addList(Task task) { | ||
list.add(task); | ||
System.out.println("added: " + task.getDescription()); | ||
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. Could it better if we just use the task's string representation here instead? This would consequently remove the need for an extra getter in the Task's class |
||
System.out.print("You have: " + list.size() + " task(s)"); | ||
} | ||
|
||
private static void deleteTask(int i) { | ||
int index = i - 1; | ||
System.out.println("removed: " + list.get(index).toString()); | ||
System.out.print("You have: " + (list.size() - 1)+ " task(s)"); | ||
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. Missing trailing whitespace before '+'. This is a common issue found in other part of the codebase too. |
||
list.remove(index); | ||
|
||
} | ||
|
||
private static void parseIn(List<String> parm) throws DukeException { | ||
int byIndex; | ||
int fromIndex; | ||
String description; | ||
List<String> l; | ||
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.
|
||
String deadline; | ||
|
||
switch(parm.get(0)){ | ||
case "list": | ||
showList(); | ||
break; | ||
case "todo": | ||
l = parm.subList(1, parm.size()); | ||
if (parm.size() == 1) { | ||
throw new DukeException("to do must have description"); | ||
} | ||
|
||
description = String.join(" ", l); | ||
addList(new Todo(description)); | ||
|
||
break; | ||
|
||
case "deadline": | ||
try{ | ||
//find the /by keyword | ||
byIndex = parm.indexOf("/by"); | ||
l = parm.subList(1, byIndex); | ||
description = String.join(" ", l); | ||
l = parm.subList(byIndex + 1, parm.size()); | ||
deadline = String.join(" ", l); | ||
addList(new Deadline(description,deadline)); | ||
} | ||
catch (IllegalArgumentException e) { | ||
throw new DukeException(e); | ||
} | ||
|
||
catch (Exception e) { | ||
throw new DukeException(e); | ||
} | ||
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. How about shifting your |
||
break; | ||
case "event": | ||
try{ | ||
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 leave a space between the try and starting curly bracket? |
||
fromIndex = parm.indexOf("/from"); | ||
byIndex = parm.indexOf("/to"); | ||
l = parm.subList(1, fromIndex); | ||
description = String.join(" ", l); | ||
|
||
List<String> f = parm.subList(fromIndex + 1, byIndex); | ||
String fDescription = String.join(" ", f); | ||
|
||
List<String> t = parm.subList(byIndex + 1, parm.size()); | ||
String tDescription = String.join(" ", l); | ||
tDescription = String.join(" ", t); | ||
addList(new Event(description, fDescription, tDescription)); | ||
} | ||
catch (IllegalArgumentException e) { | ||
throw new DukeException(e); | ||
} | ||
|
||
|
||
catch (Exception e) { | ||
throw new DukeException(e); | ||
} | ||
|
||
break; | ||
|
||
case "mark": | ||
try{ | ||
markTask(Integer.parseInt(parm.get(1)), true); | ||
} | ||
catch (IndexOutOfBoundsException e) { | ||
throw new DukeException(e); | ||
|
||
} | ||
catch (NumberFormatException e) { | ||
throw new DukeException(e); | ||
|
||
} | ||
catch (Exception e) { | ||
throw new DukeException(e); | ||
} | ||
|
||
break; | ||
case "unmark": | ||
try{ | ||
markTask(Integer.parseInt(parm.get(1)), false); | ||
} | ||
catch (IndexOutOfBoundsException e) { | ||
throw new DukeException(e); | ||
|
||
} | ||
catch (NumberFormatException e) { | ||
throw new DukeException(e); | ||
|
||
} | ||
catch (Exception e) { | ||
throw new DukeException(e); | ||
} | ||
|
||
break; | ||
|
||
case "delete": | ||
try{ | ||
deleteTask(Integer.parseInt(parm.get(1))); | ||
} | ||
catch (IndexOutOfBoundsException e) { | ||
throw new DukeException(e); | ||
|
||
} | ||
catch (NumberFormatException e) { | ||
throw new DukeException(e); | ||
|
||
} | ||
catch (Exception e) { | ||
throw new DukeException(e); | ||
} | ||
|
||
break; | ||
|
||
default: | ||
throw new DukeException(); | ||
|
||
} | ||
|
||
} | ||
|
||
public static void main(String[] args) throws DukeException{ | ||
Duke duke = new Duke(); | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println("I will remember things now"); | ||
|
||
while(true) { | ||
System.out.print('\n'); | ||
Scanner sc = new Scanner(System.in); | ||
String in = sc.nextLine(); | ||
|
||
if (in.equals("bye")) { | ||
System.out.println("No don't go!!"); | ||
break; | ||
} | ||
|
||
line(in.length()); | ||
String[] parmArr = in.split("\\s+"); | ||
List<String> parm = Arrays.asList(parmArr); | ||
try { | ||
parseIn(parm); | ||
} | ||
catch (DukeException e) { | ||
|
||
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 see that the DukeException will send a message to user when it is created, I believe adding a comment for this behaviour would be helpful for others to understand why there is an empty catch block. |
||
} | ||
|
||
line(in.length()); | ||
|
||
} | ||
|
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public class DukeException extends Exception { | ||
|
||
public DukeException() { | ||
System.out.println("idk what you are saying"); | ||
} | ||
|
||
public DukeException(String problem) { | ||
System.out.println(problem); | ||
} | ||
|
||
public DukeException(Throwable cause) { | ||
System.out.println(cause); | ||
} | ||
|
||
public DukeException(IllegalArgumentException i) { | ||
System.out.println("did you forget a keyword? ie /by /to /from"); | ||
} | ||
|
||
public DukeException(IndexOutOfBoundsException i) { | ||
System.out.println("Did you try to mark a task that is not in the list?"); | ||
} | ||
|
||
public DukeException(NumberFormatException i) { | ||
System.out.println("You must input a number"); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Event extends Task { | ||
|
||
protected String from; | ||
protected String to; | ||
public Event(String description, String from, String to) { | ||
super(description); | ||
this.from = from; | ||
this.to = to; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
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. This could be set to private since it is only used internally within the class |
||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
|
||
public void markTask(boolean b) { | ||
isDone = b; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "[" + getStatusIcon() + "] " + description; // mark done task with X | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class Todo extends Task { | ||
|
||
protected String by; | ||
public Todo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
} |
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.
There seems to be extra indentation for every line in not just this file, but the other files as well.