Skip to content

Commit

Permalink
Fix bugs from peer review.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsaf1 committed Oct 11, 2022
1 parent 62b0ad5 commit aaaf133
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 171 deletions.
8 changes: 3 additions & 5 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
1.[T][ ]
2.[T][ ] 11
3.[D][ ] today(by:today)
4.[T][ ] 2
5.[T][ ]
1.[T][ ] read books
2.[D][X] return books (by: 16th Sept 2022 2359)
3.[E][ ] books signing (at: Monday 2pm - 4pm)
Binary file modified src/main/Resources/Images/Spongebob.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/Resources/Images/Squidward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/main/Resources/view/DialogBox.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>

<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="dialog" text="Label" wrapText="true" />
<Label fx:id="dialog" alignment="CENTER" contentDisplay="CENTER" prefHeight="101.0" prefWidth="191.0" text="Label" wrapText="true">
<font>
<Font name="Modern No. 20" size="12.0" />
</font></Label>
<ImageView fx:id="displayPicture" fitHeight="99.0" fitWidth="99.0" pickOnBounds="true" preserveRatio="true" />
</children>
<padding>
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public Deadline(String description, String by) {
}

/**
* Method that overrides Java.toString() method to convert the Deadline
* task as a string.
* Method that overrides Java.toString() method to convert the Deadline task as a string.
* @return A string of the Deadline task.
*/
@Override
Expand All @@ -34,8 +33,7 @@ public String toString() {
}

/**
* Method to obtain the date as an attribute of its own rather than a string
* in the format of "MMM d yyyy".
* Method to obtain the date as an attribute of its own rather than a string in the format of "MMM d yyyy".
*/
public void getDate() throws Exception {
try {
Expand Down
89 changes: 54 additions & 35 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,69 +33,65 @@ public Duke () {

/**
* Method that generates a response to the input from the user.
*
* @param input the text given from the user.
* @return A string of response from Duke.
* @throws DukeException
* @throws IOException
*/
String getResponse(String input) throws DukeException, IOException {
if (input.equals("hi")) {
String response = "Ayo wagwan, chat to me blud.";
return response;
}

if (input.equals("bye")) {
String response = "See you later fam. Ciao!";
return response;
if (input.equals("hi") || input.equals("bye")) {
return getStringForGreetings(input);
}

String[] inputByWords = input.split(" ");
String firstWord = inputByWords[0];

if (input.equals("list")) {
return taskList.list();

} else if (firstWord.equals("mark")) {
Integer indexOfTask = Integer.parseInt(inputByWords[1]);
return taskList.mark(indexOfTask);

} else if (firstWord.equals("unmark")) {
Integer indexOfTask = Integer.parseInt(inputByWords[1]);
return taskList.unmark(indexOfTask);

} else if (firstWord.equals("todo")) {
return getStringForTodo(input);

} else if (firstWord.equals("deadline")) {
return getStringForDeadline(input);

} else if (firstWord.equals("event")) {
return getStringForEvent(input);

} else if (firstWord.equals("delete")) {
Integer indexOfTask = Integer.parseInt(inputByWords[1]);
return taskList.delete(indexOfTask);

} else if (firstWord.equals("find")) {
String content = input.replace("find", "");
return taskList.find(content);

return taskList.find(input);
} else if (firstWord.equals("help")) {
String response = "";

response += "Refer to this link:\n";
String url = "https://mohamedsaf1.github.io/ip/";
response += url;
return response;

return getStringForHelp();
} else {
String response = "Oops, sorry I don't know what you are talking about :(\n" +
"I require a specific set of commands, type 'help' to know more!";
return response;
}
}

/**
* Method to get response for greetings.
* @param input the text given from the user.
* @return A string of response from Duke.
* @throws DukeException
* @throws IOException
*/
private String getStringForGreetings(String input) throws DukeException, IOException {
if (input.equals("hi")) {
String response = "Ayo wagwan, chat to me blud.";
return response;
}
if (input.equals("bye")) {
String response = "See you later fam. Ciao!";
return response;
}
throw new DukeException("Invalid input.");
}

/**
* Method to get response for Todo task inputs.
* @param input the text given from the user.
Expand All @@ -104,11 +100,16 @@ String getResponse(String input) throws DukeException, IOException {
* @throws IOException
*/
private String getStringForTodo(String input) throws DukeException, IOException {
if (input.endsWith("todo")) {
String todoConcat = input.replace("todo", "");
if (todoConcat.isBlank()) {
throw new DukeException("Oops, the description of todo cannot be empty!");
}

String todoTask = input.replaceAll("todo ", "");
String todoTask = input.replaceAll(" ", "");

if (todoTask.isBlank()) {
throw new DukeException("Oops, the description of todo cannot be empty!");
}
return taskList.todo(todoTask);
}

Expand All @@ -120,13 +121,17 @@ private String getStringForTodo(String input) throws DukeException, IOException
* @throws IOException
*/
private String getStringForDeadline(String input) throws DukeException, IOException {
if (input.endsWith("deadline")) {
throw new DukeException("Ooops, the description of deadline cannot be empty!");
String deadlineConcat = input.replace("deadline", "");
if (deadlineConcat.isBlank()) {
throw new DukeException("Oops, the description of deadline cannot be empty!");
}

String[] inputSplit = input.split("/by");
String deadlineTask = inputSplit[0].replaceAll("deadline ", "");
String deadlineTask = inputSplit[0].replaceAll(" ", "");
String deadlineBy = inputSplit[1];
if (deadlineBy.isBlank()) {
throw new DukeException("Oops, the description of deadline cannot be empty!");
}
return taskList.deadline(deadlineTask, deadlineBy);
}

Expand All @@ -138,14 +143,28 @@ private String getStringForDeadline(String input) throws DukeException, IOExcept
* @throws IOException
*/
private String getStringForEvent(String input) throws DukeException, IOException {
if (input.endsWith("event")) {
throw new DukeException("Ooops, the description of event cannot be empty!");
String eventConcat = input.replace("event", "");
if (eventConcat.isBlank()) {
throw new DukeException("Oops, the description of event cannot be empty!");
}

String[] inputSplit = input.split("/at");
String eventTask = inputSplit[0].replaceAll("event ", "");
String eventTask = inputSplit[0].replaceAll(" ", "");
String eventAt = inputSplit[1];
if (eventAt.isBlank()) {
throw new DukeException("Oops, the description of event cannot be empty!");
}
return taskList.event(eventTask, eventAt);
}

/**
* Method to get response for help input.
* @return A string of response from Duke.
*/
private String getStringForHelp() {
String response = "Refer to this link:\n";
String url = "https://mohamedsaf1.github.io/ip/";
response += url;
return response;
}
}
95 changes: 0 additions & 95 deletions src/main/java/duke/Parser.java

This file was deleted.

58 changes: 33 additions & 25 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,7 @@ public ArrayList<Task> load() throws DukeException {
throw new DukeException ("File is Empty!");

} else {
while (scanner.hasNextLine()) {
String task = scanner.nextLine();
String type = String.valueOf(task.charAt(1));
assert type.equals("T") || type.equals("E") || type.equals("D");

if (type.equals("T")) {
String currTask = task.substring(9);
Task td = new Todo(" " + currTask);
inputList.add(td);
} else if (type.equals("E")) {
int splitter = task.indexOf(" (at: ");
String currTask = task.substring(9, splitter);
String time = task.substring(splitter + 6, task.indexOf(")"));
Task ev = new Event(" " + currTask, time);
inputList.add(ev);
} else if (type.equals("D")) {
int splitter = task.indexOf(" (by: ");
String currTask = task.substring(9, splitter);
String time = task.substring(splitter + 6, task.indexOf(")"));
Task dl = new Deadline(" " + currTask, time);
inputList.add(dl);
} else {
break;
}
}
readLines(scanner);
}
} catch (FileNotFoundException e) {
File file = new File(filePath);
Expand All @@ -103,4 +79,36 @@ public ArrayList<Task> load() throws DukeException {
}
return inputList;
}

/**
* Method to analyse the lines.
* @param scanner Input from the user.
*/
public void readLines(Scanner scanner) {
while (scanner.hasNextLine()) {
String task = scanner.nextLine();
String type = String.valueOf(task.charAt(1));
assert type.equals("T") || type.equals("E") || type.equals("D");

if (type.equals("T")) {
String currTask = task.substring(9);
Task td = new Todo(" " + currTask);
inputList.add(td);
} else if (type.equals("E")) {
int splitter = task.indexOf(" (at: ");
String currTask = task.substring(9, splitter);
String time = task.substring(splitter + 6, task.indexOf(")"));
Task ev = new Event(" " + currTask, time);
inputList.add(ev);
} else if (type.equals("D")) {
int splitter = task.indexOf(" (by: ");
String currTask = task.substring(9, splitter);
String time = task.substring(splitter + 6, task.indexOf(")"));
Task dl = new Deadline(" " + currTask, time);
inputList.add(dl);
} else {
break;
}
}
}
}
Loading

0 comments on commit aaaf133

Please sign in to comment.