Skip to content

Commit

Permalink
Removing commented out bits to improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
RiyaMehta2211 committed Sep 22, 2023
1 parent 44b052e commit 94c43a3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
15 changes: 7 additions & 8 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,23 @@ private static void addEvent(String str, TaskList tasks) throws EventCommandUseE
if (!str.contains("/from")) {
throw new EventCommandUseException(str);
} else {
String fromMarker = "/from "; //mark the /from index of the string
String fromMarker = "/from ";
int firstIndex = str.indexOf(fromMarker);
int secondIndex;
String fromWhen;
String toWhen;
String workToDo = str.substring(6, firstIndex);
workToDo = workToDo.trim();
String afterFirstIndex = str.substring(firstIndex + 6);
if (!afterFirstIndex.contains("/to ")) { //to check the input of /to after /from
if (!afterFirstIndex.contains("/to ")) {
throw new EventCommandUseException(str);
} else {
String toMarker = "/to "; //mark the /to index of the string
secondIndex = afterFirstIndex.indexOf(toMarker); //to make sure we get the /to after the /from
fromWhen = afterFirstIndex.substring(0, secondIndex).trim(); //get the from timing
toWhen = afterFirstIndex.substring(secondIndex + 3).trim(); //get the to timing
String toMarker = "/to ";
secondIndex = afterFirstIndex.indexOf(toMarker);
fromWhen = afterFirstIndex.substring(0, secondIndex).trim();
toWhen = afterFirstIndex.substring(secondIndex + 3).trim();
if (fromWhen.trim().isEmpty() ||
toWhen.trim().isEmpty()) { //needs to check whether there is anything after /by
toWhen.trim().isEmpty()) {
throw new EventCommandUseException(str);
}
Task task = new Event(workToDo, LocalDateTime.parse(fromWhen, formatter),
Expand Down Expand Up @@ -303,7 +303,6 @@ else if (str.equals("list") || str.startsWith("find ")) {
throw new InvalidInputException(str);
}
} catch (java.time.format.DateTimeParseException e) {
//detect inputs that don't follow the yyyy-MM-dd HHmm format
return Ui.printException();
} catch (EmptyInputException| TaskTypeMismatchException | InvalidInputException | FileNotFoundException e) {
return Ui.printException(e.getMessage());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static void saveTasks(String filePath, TaskList tasks) throws FileNotFoun
* @return A formatted string representation of the task.
*/
static String formatTaskData(Task task) {
// Customize this method based on your Task class structure.
String str = task.saveTaskString();
return str;
}
Expand Down Expand Up @@ -92,7 +91,7 @@ public static TaskList loadTasks(String filePath) {
break;
}
}
reader.close(); // Close the reader when done.
reader.close();
} catch (FileNotFoundException e) {
System.out.println("File not found: " + e.getMessage());
} catch (IOException e) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
public class Event extends Task {
LocalDateTime startDate;
LocalDateTime endDate;
//Introducing LocalDateTime to parse the string inputs given by the user
//for the relevant date and time

/**
* Constructor to build an Event Task Object with the task description,
Expand Down

0 comments on commit 94c43a3

Please sign in to comment.