From fb71dcf53fdb22ff831c75872e2e6278474439e0 Mon Sep 17 00:00:00 2001 From: Shriya Saxena Date: Thu, 24 Oct 2019 13:50:04 +0800 Subject: [PATCH 1/6] removed launcher, main and gui --- src/main/java/Launcher.java | 10 --- src/main/java/Main.java | 130 ------------------------------- src/main/java/gui/DialogBox.java | 29 ------- 3 files changed, 169 deletions(-) delete mode 100644 src/main/java/Launcher.java delete mode 100644 src/main/java/Main.java delete mode 100644 src/main/java/gui/DialogBox.java diff --git a/src/main/java/Launcher.java b/src/main/java/Launcher.java deleted file mode 100644 index 43d64c26fb..0000000000 --- a/src/main/java/Launcher.java +++ /dev/null @@ -1,10 +0,0 @@ -import javafx.application.Application; - -/** - * A launcher class to workaround classpath issues. - */ -public class Launcher { - public static void main(String[] args) { - Application.launch(Main.class, args); - } -} diff --git a/src/main/java/Main.java b/src/main/java/Main.java deleted file mode 100644 index 0e846862fd..0000000000 --- a/src/main/java/Main.java +++ /dev/null @@ -1,130 +0,0 @@ -import javafx.application.Application; -import javafx.scene.Scene; -import javafx.scene.control.Label; -import javafx.stage.Stage; -//import javafx.application.Application; -//import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.ScrollPane; -import javafx.scene.control.TextField; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.VBox; -import javafx.scene.layout.Region; -import gui.DialogBox; -import javafx.scene.control.Label; -//import javafx.stage.Stage; - -public class Main extends Application { - private ScrollPane scrollPane; - private VBox dialogContainer; - private TextField userInput; - private Button sendButton; - private Scene scene; - - /** - * The main method of the AlphaNUS program, which instantiates a AlphaNUS instance with the filepath to the storage. - * @param args Unused. - */ - public static void main(String[] args) { - new AlphaNUS("data/AlphaNUS.txt").run(); - } - - @Override - public void start(Stage stage) { - //Step 1. Setting up required components - - //The container for the content of the chat to scroll. - scrollPane = new ScrollPane(); - dialogContainer = new VBox(); - scrollPane.setContent(dialogContainer); - - userInput = new TextField(); - sendButton = new Button("Send"); - - AnchorPane mainLayout = new AnchorPane(); - mainLayout.getChildren().addAll(scrollPane, userInput, sendButton); - - scene = new Scene(mainLayout); - - stage.setScene(scene); - stage.show(); - - // more code to be added here later - stage.setTitle("AlphaNUS"); - stage.setResizable(false); - stage.setMinHeight(500.0); - stage.setMinWidth(800.0); - - mainLayout.setPrefSize(500.0, 800.0); - - scrollPane.setPrefSize(785, 435); - scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); - scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS); - - scrollPane.setVvalue(1.0); - scrollPane.setFitToWidth(true); - - // You will need to import `javafx.scene.layout.Region` for this. - dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE); - - userInput.setPrefWidth(725.0); - - sendButton.setPrefWidth(55.0); - - AnchorPane.setTopAnchor(scrollPane, 1.0); - - AnchorPane.setBottomAnchor(sendButton, 1.0); - AnchorPane.setRightAnchor(sendButton, 1.0); - - AnchorPane.setLeftAnchor(userInput, 1.0); - AnchorPane.setBottomAnchor(userInput, 1.0); - - // more code to be added here later - sendButton.setOnMouseClicked((event) -> { - handleUserInput(); - }); - - userInput.setOnAction((event) -> { - handleUserInput(); - }); - - dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0)); - } - - /** - * Iteration 1: - * Creates a label with the specified text and adds it to the dialog container. - * @param text String containing text to add - * @return a label with the specified text that has word wrap enabled. - */ - private Label getDialogLabel(String text) { - // You will need to import `javafx.scene.control.Label`. - Label textToAdd = new Label(text); - textToAdd.setWrapText(true); - - return textToAdd; - } - - /** - * Iteration 2: - * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to - * the dialog container. Clears the user input after processing. - */ - private void handleUserInput() { - Label userText = new Label(userInput.getText()); - Label dukeText = new Label(getResponse(userInput.getText())); - dialogContainer.getChildren().addAll( - new DialogBox(userText), - new DialogBox(dukeText) - ); - userInput.clear(); - } - - /** - * You should have your own function to generate a response to user input. - * Replace this stub with your completed method. - */ - private String getResponse(String input) { - return "AlphaNUS heard: " + input; - } -} diff --git a/src/main/java/gui/DialogBox.java b/src/main/java/gui/DialogBox.java deleted file mode 100644 index 2b78a8e9f7..0000000000 --- a/src/main/java/gui/DialogBox.java +++ /dev/null @@ -1,29 +0,0 @@ -package gui; - -import javafx.geometry.Pos; -import javafx.scene.control.Label; -import javafx.scene.image.ImageView; -import javafx.scene.layout.HBox; - -/** - * The style of the dialog box shown on the UI. - */ -public class DialogBox extends HBox { - - private Label text; - private ImageView displayPicture; - - /** - * Defines the style of the dialogue between the AlphaNUS and the User. - * @param l a label for the current dialog. - */ - public DialogBox(Label l) { - text = l; - - - text.setWrapText(true); - - this.setAlignment(Pos.TOP_LEFT); - this.getChildren().addAll(text); - } -} \ No newline at end of file From 16c7ca72b78ddb5cce1cdd2fdc3a207c6708467b Mon Sep 17 00:00:00 2001 From: Shriya Saxena Date: Thu, 24 Oct 2019 22:55:42 +0800 Subject: [PATCH 2/6] History feature implemented --- data/duke.txt | Bin 323 -> 44 bytes src/main/java/AlphaNUS.java | 4 +- src/main/java/command/Parser.java | 41 ++++++++++++++------ src/main/java/command/Process.java | 26 ++++++------- src/main/java/command/Storage.java | 60 ++++++++++++++++++++--------- src/main/java/ui/Ui.java | 8 ---- 6 files changed, 83 insertions(+), 56 deletions(-) diff --git a/data/duke.txt b/data/duke.txt index 9f42cff3952514138655663f19be6a729ba74090..5163526ccfe177fcede04bea473723f1a851403a 100644 GIT binary patch literal 44 tcmYdE%}FguRVYZTOa+qq5L!W@M#0EL*U&)M$iUE2!N|zU)X>Vr0suTY3@!iw literal 323 zcmZ4UmVvdnh(S0ju`E%qv?Mb}&#|Z|vC=2AxTK=-lI+amiF2757(E$SiZiQHD+(AG z7#Pc0KqOETZ%JZtww_CBVoFYCUh3k>nsMppA9*k_FjN#VaDwGRfC~Bo>;B0_9;jnt z;EZBm%Pe-u&r9`TU` arraylist = storage.load(); <-- Giving file not found exception, to remove tasklist = new TaskList(); managermap = new HashMap(); - commandList = new ArrayList(); projectmap = new HashMap();//To replace managermap in main class run(); } @@ -56,7 +55,6 @@ public void run() { * @param args Unused. */ public static void main(String[] args) { - new AlphaNUS("..data/AlphaNUS.txt").run(); + new AlphaNUS("data/duke.txt").run(); } - } diff --git a/src/main/java/command/Parser.java b/src/main/java/command/Parser.java index b50dde4ff6..6cda9c7895 100644 --- a/src/main/java/command/Parser.java +++ b/src/main/java/command/Parser.java @@ -44,7 +44,10 @@ public static boolean parse(String input, TaskList tasklist, Ui ui, Storage stor ui.byeMessage(); ui.getIn().close(); return true; + } else if (instr.isHistory(input)) { + process.history(ui,commandList, storage); } else if (instr.isAddProject(input)) { + process.commandHistory(input, ui, storage); if (currentProject == null) { currentProject = process.addProject(input, ui, projectmap); } else { @@ -52,38 +55,47 @@ public static boolean parse(String input, TaskList tasklist, Ui ui, Storage stor } } else if (instr.isDeleteProject(input)) { Project deletedProject = process.deleteProject(input, ui, projectmap); + process.commandHistory(input, ui, storage); if (currentProject == deletedProject) { currentProject = null; } } else if (instr.isGoToProject(input)) { + if(currentProject == null){ + process.noProject(ui); + } currentProject = process.goToProject(input, ui, projectmap); - } else if (currentProject == null) { - process.noProject(ui); + process.commandHistory(input, ui, storage); } else if (instr.isList(input)) { //print out current list - process.commandHistory(input, ui, commandList,storage); ui.printList(tasklist, "list"); + process.commandHistory(input, ui, storage); } else if (instr.isDone(input)) { process.done(input, tasklist, ui); + process.commandHistory(input, ui, storage); } else if (instr.isDeadline(input)) { process.deadline(input, tasklist, ui); - storage.save(tasklist.returnArrayList()); + process.commandHistory(input, ui, storage); + //storage.save(tasklist.returnArrayList()); } else if (instr.isDoAfter(input)) { process.doAfter(input, tasklist, ui); - Storage.save(tasklist.returnArrayList()); + //Storage.save(tasklist.returnArrayList()); } else if (instr.isDeletePayment(input)) { process.deletePayment(input, managermap, ui); + process.commandHistory(input, ui, storage); //storage.save(tasklist.returnArrayList()); } else if (instr.isFind(input)) { // process.find(input, tasklist, ui); + process.commandHistory(input, ui, storage); } else if (instr.isWithinPeriodTask(input)) { process.within(input, tasklist, ui); - storage.save(tasklist.returnArrayList()); + process.commandHistory(input, ui, storage); + //storage.save(tasklist.returnArrayList()); } else if (instr.isSnooze(input)) { process.snooze(input, tasklist, ui); - storage.save(tasklist.returnArrayList()); + process.commandHistory(input, ui, storage); + //storage.save(tasklist.returnArrayList()); /* `} else if (instr.isPostpone(input)) { process.postpone(input, tasklist, ui); @@ -91,31 +103,36 @@ public static boolean parse(String input, TaskList tasklist, Ui ui, Storage stor */ } else if (instr.isReschedule(input)) { // process.reschedule(input, tasklist, ui); - storage.save(tasklist.returnArrayList()); + //storage.save(tasklist.returnArrayList()); } else if (instr.isViewSchedule(input)) { process.viewSchedule(input, tasklist, ui); + process.commandHistory(input, ui, storage); //storage.save(tasklist.returnArrayList()); } else if (instr.isReminder(input)) { //process.reminder(input, tasklist, ui); + process.commandHistory(input, ui, storage); } else if (instr.isEdit(input)) { // process.edit(input,tasklist,ui); + process.commandHistory(input, ui, storage); } else if (instr.isAddPayment(input)) { process.addPayment(input, managermap, ui); + process.commandHistory(input, ui, storage); } else if (instr.isgetpayee(input)) { process.findPayee(input, ui, managermap); + process.commandHistory(input, ui, storage); } else if (instr.isAddPayee(input)) { process.addPayee(input, managermap, ui); + process.commandHistory(input, ui, storage); } else if (instr.isDeletePayee(input)) { process.deletePayee(input, managermap, ui); - process.commandHistory(input, ui, commandList, storage); + process.commandHistory(input, ui, storage); } else if (instr.isInvoice(input)) { process.inVoice(input, tasklist, ui); - } else if (instr.isHistory(input)) { - process.commandHistory(input, ui,commandList, storage); + process.commandHistory(input, ui, storage); } else { throw new AlphaNUSException(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-("); } - } catch (AlphaNUSException | IOException e) { + } catch (AlphaNUSException e) { process.homePageMessage(currentProject.projectname, projectmap.size(), ui); } catch (NullPointerException e) { process.homePageMessage(null, projectmap.size(), ui); diff --git a/src/main/java/command/Process.java b/src/main/java/command/Process.java index 492874ca6d..1cc7024e4c 100644 --- a/src/main/java/command/Process.java +++ b/src/main/java/command/Process.java @@ -12,9 +12,6 @@ import task.WithinPeriodTask; import ui.Ui; -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -480,21 +477,20 @@ public void inVoice(String input, TaskList tasklist, Ui ui) { } } - public void commandHistory(String input, Ui ui, ArrayList commandList, Storage storage) throws IOException { - if (!input.equals("history")) { + public void commandHistory(String input, Ui ui, Storage storage) { Calendar cal = Calendar.getInstance(); Date date = cal.getTime(); - DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); + DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); String formattedDate = dateFormat.format(date); - String command_time = input + " at " + formattedDate; - //commandList.add(command_time); - FileWriter fw = new FileWriter(String.valueOf(storage)); + String command_time = input + " | " + formattedDate; + storage.save(command_time); + /*FileWriter fw = new FileWriter(String.valueOf(storage)); BufferedWriter bw = new BufferedWriter(fw); bw.write(command_time); - } - else{ - //ui.printArrayList(commandList); - ui.printTxtfile(String.valueOf(storage)); - } - } + */ + } + public void history(Ui ui, ArrayList commandList, Storage storage){ + commandList = storage.load(); + ui.printArrayList(commandList); + } } \ No newline at end of file diff --git a/src/main/java/command/Storage.java b/src/main/java/command/Storage.java index e0c84b20ba..7db3717769 100644 --- a/src/main/java/command/Storage.java +++ b/src/main/java/command/Storage.java @@ -1,11 +1,6 @@ package command; -import java.io.ObjectOutputStream; -import java.io.FileOutputStream; -import java.io.EOFException; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; +import java.io.*; import task.Task; import java.util.ArrayList; @@ -18,6 +13,7 @@ public class Storage { /** * Creates a Storage instance with the required attributes. + * * @param filepath Filepath to the storage file. */ public Storage(String filepath) { @@ -26,21 +22,31 @@ public Storage(String filepath) { /** * Loads an ArrayList containing the Task object from the storage file. + * * @return The ArrayList containing the Task object. */ - public static ArrayList load() { + public static ArrayList load() { try { + String line; + ArrayList List = new ArrayList(); + FileReader fileReader = new FileReader(filepath); + BufferedReader bufferedReader = new BufferedReader(fileReader); - FileInputStream file = new FileInputStream(filepath); + while ((line = bufferedReader.readLine()) != null) { + List.add(line); + } + + bufferedReader.close(); + return List; + /*FileInputStream file = new FileInputStream(filepath); ObjectInputStream out = new ObjectInputStream(file); - ArrayList arraylist = (ArrayList) out.readObject(); + ArrayList commandList = (ArrayList) out.readObject(); out.close(); - file.close(); + */ - return arraylist; - } catch (EOFException e) { + } /*catch (EOFException e) { System.out.println("File is empty"); } catch (IOException ioe) { ioe.printStackTrace(); @@ -48,23 +54,41 @@ public static ArrayList load() { System.out.println("Class not found"); c.printStackTrace(); } - return new ArrayList(); + return new ArrayList(); + */ catch (FileNotFoundException ex) { + System.out.println("Unable to open file '" + filepath + "'"); + } catch (IOException ex) { + System.out.println("Error reading file '" + filepath + "'"); + } + return new ArrayList(); } /** * Saves the tasklist of the user as an ArrayList containing the task object. - * @param tasklist Tasklist of the user. + * */ - public static void save(ArrayList tasklist) { + public static void save(String str) { try { - FileOutputStream file = new FileOutputStream(filepath); + FileWriter fileWriter = new FileWriter(filepath, true); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + bufferedWriter.newLine(); + /*for (int i = 0; i < tasklist.size(); i = i + 1) { + bufferedWriter.write(tasklist.get(i)); + } + */ + bufferedWriter.write(str); + bufferedWriter.close(); + /*FileOutputStream file = new FileOutputStream(filepath); ObjectOutputStream out = new ObjectOutputStream(file); out.writeObject(tasklist); out.close(); file.close(); } catch (IOException ioe) { ioe.printStackTrace(); + } + */ + } catch (IOException ex) { + System.out.println("Error writing to file '" + filepath + "'"); } } - -} +} \ No newline at end of file diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 12e3c2f23d..2ee1c41aba 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -153,14 +153,6 @@ public void printArrayList(ArrayList list1) { } } - public void printTxtfile(String storage) throws IOException { - BufferedReader br = new BufferedReader(new FileReader(storage)); - String line = null; - while ((line = br.readLine()) != null) { - System.out.println(line); - } - } - /** * Prints the list of payments of a payee. * @param paymentList paymentList of the payee. From 52bf409e30c65fcf5a28ee5b8f8ab124388a0b44 Mon Sep 17 00:00:00 2001 From: Shriya Saxena Date: Thu, 24 Oct 2019 23:16:20 +0800 Subject: [PATCH 3/6] resolve checkstyle error --- src/main/java/command/Parser.java | 10 +++++----- src/main/java/command/Process.java | 26 ++++++++++++++------------ src/main/java/command/Storage.java | 30 ++++++++++++++++++------------ src/main/java/ui/Ui.java | 4 ++++ 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/main/java/command/Parser.java b/src/main/java/command/Parser.java index 6cda9c7895..57f71b63a9 100644 --- a/src/main/java/command/Parser.java +++ b/src/main/java/command/Parser.java @@ -33,11 +33,12 @@ public class Parser { * @param tasklist Tasklist of the user. * @param ui Ui that interacts with the user. * @param storage Storage for the Tasklist. - * @param commandList + * @param commandList List of input commands. * @return Returns boolean variable to indicate when to stop parsing for input. * @throws AlphaNUSException if input is not valid. */ - public static boolean parse(String input, TaskList tasklist, Ui ui, Storage storage, HashMap managermap, ArrayList commandList, HashMap projectmap) { + public static boolean parse(String input, TaskList tasklist, Ui ui, Storage storage, HashMap managermap, + ArrayList commandList, HashMap projectmap) { try { if (instr.isBye(input)) { //print bye message @@ -60,15 +61,14 @@ public static boolean parse(String input, TaskList tasklist, Ui ui, Storage stor currentProject = null; } } else if (instr.isGoToProject(input)) { - if(currentProject == null){ + if (currentProject == null) { process.noProject(ui); } currentProject = process.goToProject(input, ui, projectmap); process.commandHistory(input, ui, storage); } else if (instr.isList(input)) { - //print out current list ui.printList(tasklist, "list"); - process.commandHistory(input, ui, storage); + process.commandHistory(input, ui, storage); } else if (instr.isDone(input)) { process.done(input, tasklist, ui); process.commandHistory(input, ui, storage); diff --git a/src/main/java/command/Process.java b/src/main/java/command/Process.java index 1cc7024e4c..1b9722584f 100644 --- a/src/main/java/command/Process.java +++ b/src/main/java/command/Process.java @@ -476,20 +476,22 @@ public void inVoice(String input, TaskList tasklist, Ui ui) { ui.exceptionMessage(" ☹ OOPS!!! Please input the correct command format (refer to user guide)"); } } - + /** + * processes the input command and stores it in a text file. + * @param input Input from the user. + * @param ui Ui that interacts with the user. + * @param storage Storage that stores the input commands entered by the user. + */ public void commandHistory(String input, Ui ui, Storage storage) { - Calendar cal = Calendar.getInstance(); - Date date = cal.getTime(); - DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); - String formattedDate = dateFormat.format(date); - String command_time = input + " | " + formattedDate; - storage.save(command_time); - /*FileWriter fw = new FileWriter(String.valueOf(storage)); - BufferedWriter bw = new BufferedWriter(fw); - bw.write(command_time); - */ + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); + String formattedDate = dateFormat.format(date); + String commandTime = input + " | " + formattedDate; + storage.save(commandTime); } - public void history(Ui ui, ArrayList commandList, Storage storage){ + + public void history(Ui ui, ArrayList commandList, Storage storage) { commandList = storage.load(); ui.printArrayList(commandList); } diff --git a/src/main/java/command/Storage.java b/src/main/java/command/Storage.java index 7db3717769..d704c1e09b 100644 --- a/src/main/java/command/Storage.java +++ b/src/main/java/command/Storage.java @@ -1,8 +1,13 @@ package command; -import java.io.*; - import task.Task; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; /** @@ -28,16 +33,16 @@ public Storage(String filepath) { public static ArrayList load() { try { String line; - ArrayList List = new ArrayList(); + ArrayList list = new ArrayList(); FileReader fileReader = new FileReader(filepath); BufferedReader bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { - List.add(line); + list.add(line); } bufferedReader.close(); - return List; + return list; /*FileInputStream file = new FileInputStream(filepath); ObjectInputStream out = new ObjectInputStream(file); @@ -46,7 +51,13 @@ public static ArrayList load() { out.close(); */ - } /*catch (EOFException e) { + } catch (FileNotFoundException ex) { + System.out.println("Unable to open file '" + filepath + "'"); + } catch (IOException ex) { + System.out.println("Error reading file '" + filepath + "'"); + } + return new ArrayList(); + /*catch (EOFException e) { System.out.println("File is empty"); } catch (IOException ioe) { ioe.printStackTrace(); @@ -55,12 +66,7 @@ public static ArrayList load() { c.printStackTrace(); } return new ArrayList(); - */ catch (FileNotFoundException ex) { - System.out.println("Unable to open file '" + filepath + "'"); - } catch (IOException ex) { - System.out.println("Error reading file '" + filepath + "'"); - } - return new ArrayList(); + */ } /** diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 2ee1c41aba..b9230488e0 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -147,6 +147,10 @@ public void printList(TaskList list, String command) { System.out.print(line); } + /** + * prints the list of input commands entered by the user. + * @param list1 list of input commands entered by the user. + */ public void printArrayList(ArrayList list1) { for (int i = 0; i < list1.size(); i = i + 1) { System.out.println(list1.get(i)); From ab10a32ca8ca477363002cc7ee371fb5490ee348 Mon Sep 17 00:00:00 2001 From: Shriya Saxena Date: Thu, 24 Oct 2019 23:20:47 +0800 Subject: [PATCH 4/6] resolve checkstyle error --- src/main/java/command/Parser.java | 4 ++-- src/main/java/command/Process.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/command/Parser.java b/src/main/java/command/Parser.java index 57f71b63a9..cc09c21177 100644 --- a/src/main/java/command/Parser.java +++ b/src/main/java/command/Parser.java @@ -37,8 +37,8 @@ public class Parser { * @return Returns boolean variable to indicate when to stop parsing for input. * @throws AlphaNUSException if input is not valid. */ - public static boolean parse(String input, TaskList tasklist, Ui ui, Storage storage, HashMap managermap, - ArrayList commandList, HashMap projectmap) { + public static boolean parse(String input, TaskList tasklist, Ui ui, Storage storage, ArrayList commandList, + HashMap managermap, HashMap projectmap) { try { if (instr.isBye(input)) { //print bye message diff --git a/src/main/java/command/Process.java b/src/main/java/command/Process.java index 1b9722584f..7a3690aadc 100644 --- a/src/main/java/command/Process.java +++ b/src/main/java/command/Process.java @@ -482,6 +482,7 @@ public void inVoice(String input, TaskList tasklist, Ui ui) { * @param ui Ui that interacts with the user. * @param storage Storage that stores the input commands entered by the user. */ + public void commandHistory(String input, Ui ui, Storage storage) { Calendar cal = Calendar.getInstance(); Date date = cal.getTime(); From 28c157fcf88eb6104fb1a98b6b1bb15076642f95 Mon Sep 17 00:00:00 2001 From: Shriya Saxena Date: Thu, 24 Oct 2019 23:27:58 +0800 Subject: [PATCH 5/6] resolve compile error --- src/main/java/AlphaNUS.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/AlphaNUS.java b/src/main/java/AlphaNUS.java index 2b2dacf48b..36f18c8eee 100644 --- a/src/main/java/AlphaNUS.java +++ b/src/main/java/AlphaNUS.java @@ -33,6 +33,7 @@ public AlphaNUS(String filepath) { //ArrayList arraylist = storage.load(); <-- Giving file not found exception, to remove tasklist = new TaskList(); managermap = new HashMap(); + ArrayList commandList = storage.load(); projectmap = new HashMap();//To replace managermap in main class run(); } @@ -46,7 +47,7 @@ public void run() { boolean isExit = false; while (!isExit) { String input = ui.readInput(); - isExit = Parser.parse(input, tasklist, ui, storage, managermap, commandList, projectmap); + isExit = Parser.parse(input, tasklist, ui, storage, commandList, managermap, projectmap); } } From 70144434cb56d4dec93949cdb675df6e58566086 Mon Sep 17 00:00:00 2001 From: lijiayu980606 Date: Thu, 24 Oct 2019 23:34:14 +0800 Subject: [PATCH 6/6] Added fund class and implemented setFund/addFund funtion --- src/main/java/AlphaNUS.java | 5 +- src/main/java/command/Instruction.java | 8 +++ src/main/java/command/Parser.java | 7 ++- src/main/java/command/Process.java | 31 +++++++++++ src/main/java/project/Fund.java | 76 ++++++++++++++++++++++++++ src/main/java/ui/Ui.java | 23 ++++++++ 6 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 src/main/java/project/Fund.java diff --git a/src/main/java/AlphaNUS.java b/src/main/java/AlphaNUS.java index f116cc733b..bdb9bf7e36 100644 --- a/src/main/java/AlphaNUS.java +++ b/src/main/java/AlphaNUS.java @@ -2,6 +2,7 @@ import command.Storage; import common.TaskList; import payment.Payee; +import project.Fund; import project.Project; import ui.Ui; @@ -18,6 +19,7 @@ public class AlphaNUS { private static Ui ui; private static TaskList tasklist; + private static Fund fund; private static Storage storage; private static HashMap managermap; private static ArrayList commandList; @@ -32,6 +34,7 @@ public AlphaNUS(String filepath) { storage = new Storage(filepath); //ArrayList arraylist = storage.load(); <-- Giving file not found exception, to remove tasklist = new TaskList(); + fund = new Fund(); //TODO the fund need to be stored in the text file. managermap = new HashMap(); commandList = new ArrayList(); projectmap = new HashMap();//To replace managermap in main class @@ -47,7 +50,7 @@ public void run() { boolean isExit = false; while (!isExit) { String input = ui.readInput(); - isExit = Parser.parse(input, tasklist, ui, storage, managermap, commandList, projectmap); + isExit = Parser.parse(input, tasklist, ui, fund, storage, managermap, commandList, projectmap); } } diff --git a/src/main/java/command/Instruction.java b/src/main/java/command/Instruction.java index 4b7bab9180..6913de3612 100644 --- a/src/main/java/command/Instruction.java +++ b/src/main/java/command/Instruction.java @@ -96,4 +96,12 @@ public boolean isGoToProject(String input) { return input.startsWith("goto project"); } + public boolean isSetFund(String input) { + return input.startsWith("set fund"); + } + + public boolean isAddFund(String input) { + return input.startsWith("add fund"); + } + } \ No newline at end of file diff --git a/src/main/java/command/Parser.java b/src/main/java/command/Parser.java index b50dde4ff6..c570eb119f 100644 --- a/src/main/java/command/Parser.java +++ b/src/main/java/command/Parser.java @@ -5,6 +5,7 @@ import payment.Payee; import payment.PaymentManager; import payment.Payments; +import project.Fund; import project.Project; import task.Deadline; import task.DoAfterTasks; @@ -37,7 +38,7 @@ public class Parser { * @return Returns boolean variable to indicate when to stop parsing for input. * @throws AlphaNUSException if input is not valid. */ - public static boolean parse(String input, TaskList tasklist, Ui ui, Storage storage, HashMap managermap, ArrayList commandList, HashMap projectmap) { + public static boolean parse(String input, TaskList tasklist, Ui ui, Fund fund, Storage storage, HashMap managermap, ArrayList commandList, HashMap projectmap) { try { if (instr.isBye(input)) { //print bye message @@ -112,6 +113,10 @@ public static boolean parse(String input, TaskList tasklist, Ui ui, Storage stor process.inVoice(input, tasklist, ui); } else if (instr.isHistory(input)) { process.commandHistory(input, ui,commandList, storage); + } else if (instr.isSetFund(input)) { + process.setFund(input, ui, fund); + } else if (instr.isAddFund(input)) { + process.addFund(input, ui, fund); } else { throw new AlphaNUSException(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-("); } diff --git a/src/main/java/command/Process.java b/src/main/java/command/Process.java index 492874ca6d..ccd3ac1dc5 100644 --- a/src/main/java/command/Process.java +++ b/src/main/java/command/Process.java @@ -4,6 +4,7 @@ import payment.Payee; import payment.PaymentManager; import payment.Payments; +import project.Fund; import project.Project; import project.ProjectManager; import task.Deadline; @@ -106,6 +107,36 @@ public Project goToProject(String input, Ui ui, HashMap project return projectmap.get(projectname); } + /** + * Process the set fund command to set a fund to all projects + * Command format: set fund am/AMOUNT_OF_FUND. + * @param input Input from the user. + * @param ui Ui that interacts with the user. + */ + public void setFund(String input, Ui ui, Fund fund){ + String[] split = input.split("am/", 2); + Double amount = Double.parseDouble(split[1]); + if (fund.getFund() == -1) { + fund.setFund(amount); + ui.printSetFundMessage(fund); + } else { + ui.exceptionMessage(" ☹ OOPS!!! The fund id set already."); + } + } + + /** + * Process the add fund command to add fund value to all projects + * Command format: add fund add/AMOUNT_OF_FUND. + * @param input Input from the user. + * @param ui Ui that interacts with the user. + */ + public void addFund(String input, Ui ui, Fund fund){ + String[] split = input.split("add/", 2); + Double amount = Double.parseDouble(split[1]); + fund.addFund(amount); + ui.printAddFundMessage(fund, amount); + } + /** * Processes the find command and outputs a list of payments from the payee name given. * @param input Input from the user. diff --git a/src/main/java/project/Fund.java b/src/main/java/project/Fund.java new file mode 100644 index 0000000000..f6ae530934 --- /dev/null +++ b/src/main/java/project/Fund.java @@ -0,0 +1,76 @@ +package project; + +/** + * State the fund of the project + */ +public class Fund { + private double fund; + private double fundTaken; + private double fundRemaining; + + /** + * Instantiates the fund object. + */ + public Fund( ) { + this.fund = -1; + this.fundTaken = 0; + this.fundRemaining = fund; + } + + /** + * set fund (again) + * @param fund a double number input by the user. + */ + public void setFund(double fund) { + this.fund = fund; + } + + /** + * take fund from the total fund. + * @param amount a double number input by the user. + */ + public void takeFund(double amount) { + this.fundTaken = this.fundTaken + amount; + this.fundRemaining = this.fundRemaining - amount; + } + + /** + * add a value to the total fund. + * @param amount a double number input by the user. + */ + public void addFund(double amount) { + this.fund = this.fund + amount; + this.fundRemaining = this.fundRemaining + amount; + } + + /** + * get the private attribute fund. + * @return the attribute fund. + */ + public double getFund() { + return fund; + } + + /** + * get the private attribute fundTaken. + * @return the attribute fundTaken. + */ + public double getFundTaken() { + return fundTaken; + } + + /** + * get the private attribute fundRemaining. + * @return the attribute fundRemaining. + */ + public double getFundRemaining(){ + return fundRemaining; + } + + + public String giveFund(){ + return "\t" + "Total Fund = " + getFund() + "\n" + + "\t" + "Allocated Fund = " + getFundTaken() + "\n" + + "\t" + "Remaining Fund = " + getFundRemaining() + "\n"; + } +} diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 12e3c2f23d..4cc89eb2b3 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -4,6 +4,7 @@ import common.TaskList; import payment.Payee; import payment.Payments; +import project.Fund; import project.Project; import task.Task; @@ -321,6 +322,28 @@ public void printdeletePayeeMessage(String name, Payee payee, int payeesize) { System.out.print(line); } + /** + * Prints message of adding a fund to all projects + * @param fund the fund for all projects + */ + public void printSetFundMessage(Fund fund) { + System.out.print(line); + System.out.println("\t" + "Got it. I've set overall fund as follow:"); + System.out.print(fund.giveFund()); + System.out.print(line); + } + + /** + * Prints message of adding a fund to all projects + * @param fund the fund for all projects + */ + public void printAddFundMessage(Fund fund, double amount) { + System.out.print(line); + System.out.println("\t" + "Got it. I've add " + amount + "to the fund. The new fund is as follow:"); + System.out.print(fund.giveFund()); + System.out.print(line); + } + /** * Prints out the statement of accounts. * @param managermap managermap containing Payee and Payments information.