Skip to content
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

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
11b5c57
finish level-1
MrJeremyKhoo Jan 23, 2023
acf0f45
finish l2
MrJeremyKhoo Jan 24, 2023
f4b87a7
done lvl3
MrJeremyKhoo Jan 25, 2023
f416739
done level 4
MrJeremyKhoo Jan 25, 2023
ab0a146
finish level-4
MrJeremyKhoo Jan 25, 2023
377d098
finish level 6
MrJeremyKhoo Jan 25, 2023
50f6250
Level-7
MrJeremyKhoo Jan 31, 2023
8672b06
level-8
MrJeremyKhoo Feb 1, 2023
8caf430
Merge branch 'branch-Level-7'
MrJeremyKhoo Feb 1, 2023
bf2a6b8
fix bug with event date parsing
MrJeremyKhoo Feb 1, 2023
16a25aa
to merge l8 for auto grader
MrJeremyKhoo Feb 1, 2023
ac27e67
Merge branch 'branch-Level-8'
MrJeremyKhoo Feb 1, 2023
5ec800b
Merge gradle support branch
MrJeremyKhoo Feb 1, 2023
3b6f151
chang tab to 4 space
MrJeremyKhoo Feb 2, 2023
6a80409
gradle stylecheck
MrJeremyKhoo Feb 2, 2023
5cafe0a
add gradle
MrJeremyKhoo Feb 2, 2023
a362945
fixed style
MrJeremyKhoo Feb 9, 2023
eef2648
more oop
MrJeremyKhoo Feb 10, 2023
57f2ea8
A-Packages
MrJeremyKhoo Feb 11, 2023
4a42fa7
JUnit
MrJeremyKhoo Feb 12, 2023
b242f82
Revert "more oop"
MrJeremyKhoo Feb 12, 2023
0610e23
Revert "A-Packages"
MrJeremyKhoo Feb 12, 2023
b1a8543
Merge branch 'master' into alt-history
MrJeremyKhoo Feb 12, 2023
dff0749
add packages
MrJeremyKhoo Feb 12, 2023
0e229bd
java doc
MrJeremyKhoo Feb 12, 2023
2b3ac2f
add find feature
MrJeremyKhoo Feb 12, 2023
8d5aa19
stylecheck graddle
MrJeremyKhoo Feb 12, 2023
3afb857
merge conflict
MrJeremyKhoo Feb 12, 2023
46737fb
ready for gradle build
MrJeremyKhoo Feb 13, 2023
54dfb51
before add UI images
MrJeremyKhoo Feb 14, 2023
18ed672
JFX tutorial p3
MrJeremyKhoo Feb 14, 2023
04f09c3
Level 10
MrJeremyKhoo Feb 15, 2023
02cf756
Fix exception
MrJeremyKhoo Feb 19, 2023
7e4cc29
fix task string update
MrJeremyKhoo Feb 19, 2023
ced7eda
assertion branch
MrJeremyKhoo Feb 19, 2023
61219b6
Merge pull request #2 from jeremykhoo-NUS/branch-A-Assertions
MrJeremyKhoo Feb 19, 2023
8515b69
bad style
MrJeremyKhoo Feb 19, 2023
7d65475
fix arrowhead indentation
MrJeremyKhoo Feb 19, 2023
802b202
Merge pull request #3 from jeremykhoo-NUS/branch-A-CodingQuality
MrJeremyKhoo Feb 19, 2023
27015d1
to merge for level 10
MrJeremyKhoo Feb 20, 2023
7a87b02
Merge branch 'branch-Level-10'
MrJeremyKhoo Feb 20, 2023
6823422
BCD-Extension
MrJeremyKhoo Feb 20, 2023
3325650
added UI and UG
MrJeremyKhoo Feb 20, 2023
006442d
readme
MrJeremyKhoo Feb 20, 2023
94819eb
Update README.md
MrJeremyKhoo Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ bin/

/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT
*.class
token
13 changes: 13 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Deadline extends Task {

protected String by;

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.

public Deadline(String description, String by) {
super(description);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
Copy link

Choose a reason for hiding this comment

The 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...

}
}
203 changes: 202 additions & 1 deletion src/main/java/Duke.java
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;
Copy link

Choose a reason for hiding this comment

The 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());
Copy link

Choose a reason for hiding this comment

The 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)");
Copy link

Choose a reason for hiding this comment

The 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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<String> l could be given a more descriptive variable name, similar for variable names like f and t

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);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about shifting your try-catch logic wrapped around the switch-case block instead? That would reduce some code duplication when the same exception could be thrown

break;
case "event":
try{

Choose a reason for hiding this comment

The 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) {

Copy link

Choose a reason for hiding this comment

The 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());

}


}
}
28 changes: 28 additions & 0 deletions src/main/java/DukeException.java
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");
}


}
15 changes: 15 additions & 0 deletions src/main/java/Event.java
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 + ")";
}
}
29 changes: 29 additions & 0 deletions src/main/java/Task.java
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() {
Copy link

Choose a reason for hiding this comment

The 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
}

}
12 changes: 12 additions & 0 deletions src/main/java/Todo.java
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();
}
}