Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
leowyh committed Oct 24, 2019
2 parents bf1df31 + a981c7a commit 686b773
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 233 deletions.
Binary file modified data/duke.txt
Binary file not shown.
10 changes: 6 additions & 4 deletions src/main/java/AlphaNUS.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import command.Storage;
import common.TaskList;
import payment.Payee;
import project.Fund;
import project.Project;
import ui.Ui;

Expand All @@ -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<String, Payee> managermap;
private static ArrayList<String> commandList;
Expand All @@ -32,8 +34,9 @@ public AlphaNUS(String filepath) {
storage = new Storage(filepath);
//ArrayList<Task> 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<String, Payee>();
commandList = new ArrayList<String>();
ArrayList<String> commandList = storage.load();
projectmap = new HashMap<String, Project>();//To replace managermap in main class
run();
}
Expand All @@ -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, commandList, managermap, projectmap);
}
}

Expand All @@ -56,7 +59,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();
}

}
10 changes: 0 additions & 10 deletions src/main/java/Launcher.java

This file was deleted.

130 changes: 0 additions & 130 deletions src/main/java/Main.java

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/java/command/Instruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
51 changes: 38 additions & 13 deletions src/main/java/command/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,89 +34,113 @@ 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<String, Payee> managermap, ArrayList<String> commandList, HashMap<String, Project> projectmap) {

public static boolean parse(String input, TaskList tasklist, Ui ui, Fund fund, Storage storage, ArrayList<String> commandList,
HashMap<String, Payee> managermap, HashMap<String, Project> projectmap) {
try {
if (instr.isBye(input)) {
//print bye message
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 {
process.addProject(input, ui, projectmap);
}
} 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);
storage.save(tasklist.returnArrayList());`
*/
} 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);
process.commandHistory(input, ui, storage);
} 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 :-(");
}
} catch (AlphaNUSException | IOException e) {
} catch (AlphaNUSException e) {
process.homePageMessage(currentProject.projectname, projectmap.size(), ui);
} catch (NullPointerException e) {
process.homePageMessage(null, projectmap.size(), ui);
Expand Down
Loading

0 comments on commit 686b773

Please sign in to comment.