in java please: add File Storage features where the CheckingAccount will be writ
ID: 3766095 • Letter: I
Question
in java please: add File Storage features where the CheckingAccount will be written to and read from a file when prompted by the user. The File should be loaded via a FileDialog component where the user chooses the file to load which contains the account info. Add choices to the RadioButton group for input and output from/and to the File. Whenever an account is read in from the file, it overrides the account that is currently in the computer’s memory. When the Frame is closed, the user must be prompted to save the account unless the account has not changed since the last time it was saved. Use appropriate IOException handling with throws clauses and try-catch blocks protecting all code containing file operations. here is the Checking Account that needs to be modified: here is my checking account that needs to be modified:
import java.util.ArrayList;
public class CheckingAccount {
private double balance;
private double totalServiceCharge;
private ArrayList transList;
private int transCount = 0;
private int transSize = 0;
public CheckingAccount(double initialBalance) {
balance = initialBalance;
totalServiceCharge = 0; }
public double getBalance() {
return balance; }
public void setBalance(double transAmt, int tCode) {
if(tCode==1) balance-=transAmt;
else if(tCode==2) balance+=transAmt; }
public double getServiceCharge() {
return totalServiceCharge; }
public void setServiceCharge(double currentServiceCharge) {
totalServiceCharge += currentServiceCharge; }
public void addTrans(Transaction newTrans) {
transList = new ArrayList(); transList.add(newTrans); }
public int getTransCount() {
transCount++; return transCount; }
public Transaction getTrans(int i) {
return transList.get(i); }
public int getSize() {
transSize = transList.size(); return transSize; }
}
Explanation / Answer
import java.io.IOException;
import java.util.ArrayList;
public class CheckingAccount {
private double balance;
private double totalServiceCharge;
private ArrayList transList;
private int transCount = 0;
private int transSize = 0;
public CheckingAccount(double initialBalance) {
balance = initialBalance;
totalServiceCharge = 0;
}
public double getBalance() {
return balance;
}
public void setBalance(double transAmt, int tCode) {
try {
if (tCode < 0) { //if negative number given as parameter, then we are handling with exceptionraising
throw new IOException("Input is not positive number.");
}
if (tCode == 1) {
balance -= transAmt;
} else if (tCode == 2) {
balance += transAmt;
}
} catch (IOException exception) {
System.err.println(exception.getMessage() + " ");
}
}
public double getServiceCharge() {
return totalServiceCharge;
}
public void setServiceCharge(double currentServiceCharge) {
totalServiceCharge += currentServiceCharge;
}
public void addTrans(Transaction newTrans) {
transList = new ArrayList();
transList.add(newTrans);
}
public int getTransCount() {
transCount++;
return transCount;
}
public Transaction getTrans(int i) {
return transList.get(i);
}
public int getSize() {
transSize = transList.size();
return transSize;
}
}
********As remianing getter setter methods, there is no need to add exceptions *************
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.