Skip to content

Commit

Permalink
Create JAR File
Browse files Browse the repository at this point in the history
  • Loading branch information
pratham31012002 committed Sep 1, 2022
1 parent fc2a6ec commit 8030ffe
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 56 deletions.
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

PlutoData.txt
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ test {
}

application {
mainClassName = "seedu.duke.Duke"
mainClassName = "pluto.Pluto"
}

shadowJar {
archiveBaseName = "duke"
archiveBaseName = "pluto"
archiveClassifier = null
}

Expand Down
82 changes: 45 additions & 37 deletions src/main/java/pluto/Parser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package pluto;

import pluto.command.*;
import pluto.command.AddCommand;
import pluto.command.DeleteCommand;
import pluto.command.ListCommand;
import pluto.command.ShowCommand;
import pluto.command.Command;
import pluto.command.ExitCommand;
import pluto.command.UpdateStatusCommand;

import pluto.task.Deadline;
import pluto.task.Todo;
import pluto.task.Event;
Expand Down Expand Up @@ -38,47 +45,47 @@ public static Command parse(String inputLine) throws PlutoException {
throw new PlutoException("\tOOPS!!! I'm sorry, but I don't know what that means :-(");
}
switch (enumCommand) {
case TODO:
return parseTask(textArr[1].strip(), Type.TODO);
case DEADLINE:
return parseTask(textArr[1].strip(), Type.DEADLINE);
case EVENT:
return parseTask(textArr[1].strip(), Type.EVENT);
case MARK:
return new UpdateStatusCommand(parseIdx(textArr[1]), true);
case UNMARK:
return new UpdateStatusCommand(parseIdx(textArr[1]), false);
case DELETE:
return new DeleteCommand(parseIdx(textArr[1]));
case LIST:
return new ListCommand();
case SHOW:
return new ShowCommand(parseDateOnly(textArr[1]));
case BYE:
return new ExitCommand();
default:
throw new PlutoException("\tOOPS!!! I'm sorry, but I don't know what that means :-(");
case TODO:
return parseTask(textArr[1].strip(), Type.TODO);
case DEADLINE:
return parseTask(textArr[1].strip(), Type.DEADLINE);
case EVENT:
return parseTask(textArr[1].strip(), Type.EVENT);
case MARK:
return new UpdateStatusCommand(parseIdx(textArr[1]), true);
case UNMARK:
return new UpdateStatusCommand(parseIdx(textArr[1]), false);
case DELETE:
return new DeleteCommand(parseIdx(textArr[1]));
case LIST:
return new ListCommand();
case SHOW:
return new ShowCommand(parseDateOnly(textArr[1]));
case BYE:
return new ExitCommand();
default:
throw new PlutoException("\tOOPS!!! I'm sorry, but I don't know what that means :-(");
}
}

public static Command parseTask(String input, Type type) throws PlutoException {
switch (type) {
case TODO:
return new AddCommand(new Todo(input));
case DEADLINE:
String[] arrDeadline = input.split("/by", 2);
if (arrDeadline.length == 1) {
throw new PlutoException("\tOOPS!!! The deadline date is required.");
}
return new AddCommand(new Deadline(arrDeadline[0].strip(), parseDate(arrDeadline[1].strip())));
case EVENT:
String[] arrEvent = input.split("/at", 2);
if (arrEvent.length == 1) {
throw new PlutoException("\tOOPS!!! The event date is required.");
}
return new AddCommand(new Event(arrEvent[0].strip(), parseDate(arrEvent[1].strip())));
default:
throw new PlutoException("\tOOPS!!! pluto.task.Task must be a pluto.task.Todo, pluto.task.Deadline or pluto.task.Event.");
case TODO:
return new AddCommand(new Todo(input));
case DEADLINE:
String[] arrDeadline = input.split("/by", 2);
if (arrDeadline.length == 1) {
throw new PlutoException("\tOOPS!!! The deadline date is required.");
}
return new AddCommand(new Deadline(arrDeadline[0].strip(), parseDate(arrDeadline[1].strip())));
case EVENT:
String[] arrEvent = input.split("/at", 2);
if (arrEvent.length == 1) {
throw new PlutoException("\tOOPS!!! The event date is required.");
}
return new AddCommand(new Event(arrEvent[0].strip(), parseDate(arrEvent[1].strip())));
default:
throw new PlutoException("\tOOPS!!! Task must be a Todo, Deadline or Event.");
}
}

Expand All @@ -93,6 +100,7 @@ public static LocalDateTime parseDate(String date) throws PlutoException {
try {
return LocalDateTime.parse(date, DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm"));
} catch (DateTimeParseException e) {
System.out.println(date);
throw new PlutoException("\tOOPS!!! dd-MM-yyyy HHmm date format required.");
}
}
Expand Down
39 changes: 23 additions & 16 deletions src/main/java/pluto/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,31 @@ public ArrayList<Task> load() throws PlutoException {
Scanner sc = new Scanner(file);
while (sc.hasNext()) {
String text = sc.nextLine().strip();
String[] textArr = text.split(" | ", 7);
String[] textArr = text.split("\\s+\\|\\s+", 3);
String command = textArr[0];
int lastPipe = textArr[2].lastIndexOf("|");
String date = null;
String description = null;
if (lastPipe != -1) {
date = textArr[2].substring(lastPipe + 1).strip();
description = textArr[2].substring(0, lastPipe).strip();
}
switch (command) {
case "T":
Task todo = new Todo(textArr[4]);
markTasks(todo, textArr[2]);
missions.add(todo);
break;
case "D":
Task deadline = new Deadline(textArr[4], Parser.parseDate(textArr[6]));
markTasks(deadline, textArr[2]);
missions.add(deadline);
break;
case "E":
Task event = new Event(textArr[4], Parser.parseDate(textArr[6]));
markTasks(event, textArr[2]);
missions.add(event);
break;
case "T":
Task todo = new Todo(textArr[2]);
markTasks(todo, textArr[1]);
missions.add(todo);
break;
case "D":
Task deadline = new Deadline(description, Parser.parseDate(date));
markTasks(deadline, textArr[1]);
missions.add(deadline);
break;
case "E":
Task event = new Event(description, Parser.parseDate(date));
markTasks(event, textArr[1]);
missions.add(event);
break;
}
}
} catch (IOException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pluto/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Scanner;

public class Ui {
private static final String CHATBOT = "pluto.Pluto";
private static final String CHATBOT = "Pluto";
private Scanner sc;
private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_RESET = "\u001B[0m";
Expand Down

0 comments on commit 8030ffe

Please sign in to comment.