As a follow up to Assignment1, modify the CheckingAccount class to add the follo
ID: 3728255 • Letter: A
Question
As a follow up to Assignment1, modify the CheckingAccount class to add the following instance members: an array(self expanding type) or ArrayList of Transaction objects and a int variable transCount(incremented each time a new Transaction object is created). Create a Transaction class that stores an int transNumber(will be the current value of transCount), an int transId (1 = check, 2 = deposit 3 = service charge) and a double transAmt. Prompt the user for the choice of a) entering a transaction, b) listing all transations, c) listing all checks, d) listing all deposits.(implement these options with JFrame,JLabel, JRadioButton, ButtonGroup, and a listener) The listings must go to a Dialog box. Add instance methods to the CheckingAccount class like addTrans(put a trans into the account), getTrans(get a transaction from the array) getTransCount(get the current value of transCount class variable) and any other methods you wish to implement. This program is event-driven. You cannot put all the processing steps/logic in main. You can put them in helper methods in the Main class, in the GUI objects class, or in the CheckingAccount class, so they can be called by the listener method.
New data and methods for the CheckingAccount Class
---------------------------------------------------------------------------
private ArrayList transList; // keeps a list of Transaction objects for the account
private int transCount; // the count of Transaction objects and used as the ID for each transaction
public void addTrans( Transaction newTrans) // adds a transaction object to the transList
public int gettransCount() //returns the current value of transCount;
public Transaction getTrans(int i) // returns the i-th Transaction object in the list
--------------------------------------------------------------------------
New Transaction class
public class Transaction
{
private int transNumber;
private int transId;
private double transAmt;
public Transaction(int number, int id, double amount)
{
transNumber = number;
transId = id;
transAmt = amount;
}
public int getTransNumber()
{
return transNumber;
}
public int getTransId()
{
return transId;
}
public double getTransAmount()
{
return transAmt;
}
}
Explanation / Answer
Checking Account Subclass:
public class CheckingAccount extends BankAccount {
float amtInterest;
float applyInterest;
String displayBalance;
public CheckingAccount() {
}
public CheckingAccount(String firstName, String lastName, String ssn, float balance) {
super(firstName, lastName, ssn, balance);
System.out.println("Successfully created account for " + firstName + " " + lastName + " " + accountNumber);
System.out.println(firstName + " " + lastName + ", Balance $" + balance);
}
float applyInterest () {
if (balance <= 10000) {
balance = balance * 0.1f;
}
if (balance > 10000) {
balance = 1000 + (balance * 0.02f);
}
return balance;
}
float displayBalance() {
return balance;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.