Permalink
Browse files

Addressed 2nd issue from THAT DICK IN QA, other small tweaks

  • Loading branch information...
nathanh89 committed Nov 10, 2012
1 parent b355332 commit 7bd2c9ee55fbe7b80b62b4ba95fa9dac03cd96a2
Binary file not shown.
Binary file not shown.
@@ -9,36 +9,32 @@
public class Salvation {
- private static String getInput(){
+ public void autoSave(String fileName, Budget budget, String pathToSalvation){
+ InputValidator validator = new InputValidator();
InputListener listener = new InputListener();
- String userInput = listener.listenForInput();
- return userInput;
+ ConsoleOutput.pathToSalvationCheck(pathToSalvation);
+ String validatedInput = validator.inputIsEitherYOrN(listener.listenForInput());
+ if(validatedInput.equals("y"))
+ writeBudgetToDisk(fileName, budget, pathToSalvation);
+ else if(validatedInput.equals("n")){
+ ConsoleOutput.getSaveDirectoryPath(pathToSalvation);
+ pathToSalvation = getUserSaveDirectory(pathToSalvation);
+ writeBudgetToDisk(fileName, budget, pathToSalvation);
+ }
}
- private String askForSaveDirectory(String defaultDirectory){
+ private String getUserSaveDirectory(String defaultDirectory){
String userPath = "ERROR";
while(userPath.equals("ERROR")){
InputValidator validator = new InputValidator();
- userPath = getInput();
+ InputListener listener = new InputListener();
+ userPath = listener.listenForInput();
userPath = validator.defaultDirectoryCheck(userPath, defaultDirectory);
}
return userPath;
}
-
- public void askToSaveBudget(String fileName, Budget budget, String pathToSalvation){
- InputValidator validator = new InputValidator();
- ConsoleOutput.pathToSalvationCheck(pathToSalvation);
- String validatedInput = validator.inputIsEitherYOrN(getInput());
- if(validatedInput.equals("y"))
- saveOnExit(fileName, budget, pathToSalvation);
- else if(validatedInput.equals("n")){
- ConsoleOutput.getSaveDirectoryPath(pathToSalvation);
- pathToSalvation = askForSaveDirectory(pathToSalvation);
- saveOnExit(fileName, budget, pathToSalvation);
- }
- }
-
- private void saveOnExit(String fileName, Budget budget, String pathToSalvation){
+
+ private void writeBudgetToDisk(String fileName, Budget budget, String pathToSalvation){
try{
FileOutputStream autoSave = new FileOutputStream(pathToSalvation + fileName + ".bgt");
ObjectOutputStream saveOutput = new ObjectOutputStream(autoSave);
@@ -39,7 +39,7 @@ public static void main(String args[]){
//System.out.println("Confirm correct Budget loaded:" + currentBudget.getName());
try{
- savior.askToSaveBudget(currentBudget.getName(), currentBudget, defaultDirectory);
+ savior.autoSave(currentBudget.getName(), currentBudget, defaultDirectory);
}catch (NullPointerException e){
ConsoleOutput.noBudgetToSave();
}

0 comments on commit 7bd2c9e

Please sign in to comment.