/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package retirementcalculator;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.charset.Charset;

/**
 *
 * @author derekbarrera
 */
public class Save implements Serializable {
    
    int    retirementAgeField, ageField;
    double incomeTaxRateField, capGainsTxRateField, preTaxBalanceField, postTaxBalanceField, 
           preTaxContField, postTaxContField, rateOfReturnField;
    
    public Save(int ageField, double incomeTaxRateField, int retirementAgeField, 
                      double capGainsTxRateField, double preTaxBalanceField, double postTaxBalanceField, double preTaxContField, 
                      double postTaxContField, double rateOfReturnField, File file){
        
        this.ageField = ageField;
        this.incomeTaxRateField = incomeTaxRateField;
        this.retirementAgeField = retirementAgeField;
        this.capGainsTxRateField = capGainsTxRateField;
        this.preTaxBalanceField = preTaxBalanceField;
        this.postTaxBalanceField = postTaxBalanceField;
        this.preTaxContField = preTaxContField;
        this.postTaxContField = postTaxContField;
        this.rateOfReturnField = rateOfReturnField - 1.0;
        
        saveSerializer(file);
  
    }
    
    public Save(int ageField, double incomeTaxRateField, int retirementAgeField, 
                      double capGainsTxRateField, double preTaxBalanceField, double postTaxBalanceField, double preTaxContField, 
                      double postTaxContField, double rateOfReturnField){
        
        this.ageField = ageField;
        this.incomeTaxRateField = incomeTaxRateField;
        this.retirementAgeField = retirementAgeField;
        this.capGainsTxRateField = capGainsTxRateField;
        this.preTaxBalanceField = preTaxBalanceField;
        this.postTaxBalanceField = postTaxBalanceField;
        this.preTaxContField = preTaxContField;
        this.postTaxContField = postTaxContField;
        this.rateOfReturnField = rateOfReturnField - 1.0;
  
    }
    
    public void saveSerializer(File file){
        
        Charset chars = Charset.forName("US-ASCII");
    
        String filePath = file.toPath().toString();
        System.out.println(filePath);
        Save savers;
        
            if (file != null) {        
            
                try {
                    
                    FileOutputStream fileOut =
                    new FileOutputStream(filePath);
                    ObjectOutputStream out = new ObjectOutputStream(fileOut);
                    out.writeObject(
                            
                        savers = new Save(ageField, incomeTaxRateField, retirementAgeField, 
                                         capGainsTxRateField, preTaxBalanceField, postTaxBalanceField, preTaxContField, 
                                         postTaxContField, rateOfReturnField)
                    );
                    out.close();
                    fileOut.close();
                    System.out.printf("Serialized data is saved in" + filePath);
            
                } catch (IOException e) {
                    System.out.println(e.getMessage());
                }
            }       
    }
    
}

@@ -226,24 +226,56 @@
 va.io.File;%0A
+import java.io.FileInputStream;%0A
 import java.
@@ -323,16 +323,50 @@
 eption;%0A
+import java.io.ObjectInputStream;%0A
 import j
@@ -740,24 +740,59 @@
 Field;%0A    %0A
+    public Save()%7B%0A    %0A    %7D%0A    %0A
     public S
@@ -1537,30 +1537,24 @@
 fReturnField
- - 1.0
 ;%0A        %0A 
@@ -2351,14 +2351,8 @@
 ield
- - 1.0
 ;%0A  
@@ -3321,89 +3321,8 @@
 ();%0A
-                    System.out.printf(%22Serialized data is saved in%22 + filePath);%0A
     
@@ -3478,10 +3478,777 @@
  %7D%0A    %0A
+    public Save loadSerialed(File file) throws ClassNotFoundException%7B%0A    %0A        Save input;%0A        Save output = null;%0A        %0A        try (FileInputStream fileIn = new FileInputStream(file)) %7B%0A            ObjectInputStream in = new ObjectInputStream(fileIn);%0A            input = (Save)in.readObject();%0A            output = new Save(input.ageField, input.incomeTaxRateField, input.retirementAgeField, %0A                                         input.capGainsTxRateField, input.preTaxBalanceField, input.postTaxBalanceField, input.preTaxContField, %0A                                         input.postTaxContField, input.rateOfReturnField);%0A            in.close();%0A            fileIn.close();%0A        %7Dcatch(IOException e)%7B%7D%0A    %0A        return output;%0A    %7D%0A    %0A
 %7D%0A

Add Save method, now with load as well