Question: modify the CheckingAccount class again, to become a simple derived class of the parent class Account. The Account class contains the instance variables String name
modify the CheckingAccount class again, to become a simple derived class of the parent class Account. The Account class contains the instance variables String name (the name of the person who owns the account) and double balance (the current balance of the account). There should be appropriate get methods in Account class to get the name and balance fields. The account name should appear in all reports and dialogue. The CheckingAccount class will still have the instance variables double totalServiceCharges, and Transaction [ ] transList (or ArrayListtransList). Also, create a Check class, a simple derived class of the Transaction class. The Check class will include the check number for each check transaction. The check number will be prompted for as the check is entered, and displayed in the checks listing. Also, create a Deposit class, a simple derived class of the Transaction class. The Deposit class will include the cash amount and check amount that total to the transaction amount. The cash and check amount for each deposit will be input in a new Deposit input screen. (See sample run below.) In this applications design, you should have the following classes: 1. The Main class: This creates the frame, adds the panel, and sets it visible. This program is event-driven. You cannot put all the processing steps/logic in main method. However, you can put them in helper methods in the Main class. 2. The CheckOptionsPanel class: This creates the GUI components, adds listeners, and adds to the Panel. This is the class where most of the action (driven by events) takes place. You might want to put the processing methods (to be called by the listeners) in this class, along with the declaration of the CheckingAccount instance that you are processing. 3. The CheckingAccount class: This defines the CheckingAccount object. (Please keep this class methods simple. This is the file cabinet object which will be written to a file in a later assignment.) 4. The Account class: This serves as a Parent to the CheckingAccount class. 5. The Transaction class: This defines the transactions stored in the array inside the CheckingAccount objects. It is the parent of the Check class. 6. The Check class: This defines the check number and get method for processing the check number for each check transaction. 7. The Deposit class: This defines the cash and check amounts that comprise the total deposit transaction amount.
Here is what I have so far
------------
Main.java
------------ package accounting;
/** * * @author Ares */ import javax.swing.JFrame; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("Checking Account Actions"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); CheckingAccountActions panel = new CheckingAccountActions(); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } } -------------------
CheckingAccountActions.Java -------------------- package accounting;
/** * * @author Ares */ import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat; import java.util.ArrayList; import javax.swing.*; public class CheckingAccountActions extends JPanel { public static double initialBalance, transactionAmount; public static int firstTime = 0; static CheckingAccount ca; static DecimalFormat dollar; static Transaction t; public static int check = 1, deposit = 2, serviceCharge = 3; private JLabel message; private JRadioButton transaction, listTrans, checks, deposits; ArrayList transList; public CheckingAccountActions() { initialBalance = initialBalance(); ca = new CheckingAccount(initialBalance); dollar = new DecimalFormat("#,###.00"); message = new JLabel ("Choose an action: "); message.setFont (new Font ("Helvetica", Font.BOLD, 24)); transaction = new JRadioButton("Entering a Transaction"); transaction.setBackground (Color.yellow); listTrans = new JRadioButton("Listing All Transactions"); listTrans.setBackground(Color.yellow); checks = new JRadioButton("Listing All Checks"); checks.setBackground(Color.yellow); deposits = new JRadioButton("Listing All Deposits"); deposits.setBackground(Color.yellow); ButtonGroup group = new ButtonGroup(); group.add(transaction); group.add(listTrans); group.add(checks); group.add(deposits); CheckingAccountActionsListener listener = new CheckingAccountActionsListener(); transaction.addActionListener(listener); listTrans.addActionListener(listener); checks.addActionListener(listener); deposits.addActionListener(listener); add(message); add(transaction); add(listTrans); add(checks); add(deposits); setBackground(Color.YELLOW); setPreferredSize (new Dimension(250, 180)); } private class CheckingAccountActionsListener implements ActionListener { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); int transactionCode; double transAmt = 0; int i = 0; if(source==transaction) { transactionCode = getTransCode(); t = new Transaction(ca.getTransCount(),transactionCode,transAmt); ca.addTrans(t); switch(transactionCode) { case 1: transAmt = getTransAmt(); ca.setBalance(transAmt, transactionCode); processCheck(transAmt); JOptionPane.showMessageDialog(null, transList.get(i)); break; case 2: transAmt = getTransAmt(); ca.setBalance(transAmt, transactionCode); processDeposit(transAmt); JOptionPane.showMessageDialog(null, transList.get(i)); break; case 0: JOptionPane.showMessageDialog(null, "Transaction: End " + "Current Balance: $" + ca.getBalance() + " " + "Total Service Charge: $" + dollar.format(ca.getServiceCharge()) + " " + "Final Balance: $" + dollar.format(ca.getBalance() - ca.getServiceCharge())); break; default: JOptionPane.showMessageDialog(null, "Invalid Choice. Enter Again."); } } else if(source==listTrans) { int types = 0; int nums = 0; double amount = 0; String line; line = String.format("List All Transactions" + " " + "ID Type Amount" + " "); for(int index = 0; index < ca.getSize(); index++) { types = ca.getTrans(index).getTransId(); nums = ca.getTrans(index).getTransNumber(); amount = ca.getTrans(index).getTransAmount(); line += String.format("%-10s %3d %10s", nums,types,amount) + " "; } JTextArea text = new JTextArea(line); text.setBorder(null); text.setOpaque(false); text.setFont(new Font("Monospaced", Font.PLAIN, 14)); JOptionPane.showMessageDialog(null, text); } else if(source==checks) { String line = String.format("Checks made: "); JTextArea text = new JTextArea(line); text.setBorder(null); text.setOpaque(false); text.setFont(new Font("Monospaced", Font.PLAIN, 14) ); JOptionPane.showMessageDialog(null, text); } else if(source==deposits) { String line = String.format("Deposits made: "); JTextArea text = new JTextArea(line); text.setBorder(null); text.setOpaque(false); text.setFont(new Font("Monospaced", Font.PLAIN, 14) ); JOptionPane.showMessageDialog(null, text); } } } public static int getTransCode() { int code; String userInput; userInput=JOptionPane.showInputDialog("Enter the transaction code: "+ "1) Check 2) Deposit 0) Exit the program"); code=Integer.parseInt(userInput); return code; } public static double initialBalance() { double initialBalance; String userInput; userInput = JOptionPane.showInputDialog("Enter initial account balance :"); initialBalance = Double.parseDouble(userInput); return initialBalance; } public static double getTransAmt() { double amount; String userInput; userInput=JOptionPane.showInputDialog("Enter the transaction amount: "); amount=Double.parseDouble(userInput); return amount; } public static double processCheck(double transAmt) { ca.setBalance(transAmt, 1); ca.setServiceCharge(0.15); if(ca.getBalance()<500) { if(firstTime==0) { ca.setServiceCharge(5.00); JOptionPane.showMessageDialog(null,"Transaction: Check in Amount of $" +transactionAmount+ " " +"Current Balance: $" + dollar.format(ca.getBalance()) + " "+"Service Charge: Check --- charge $0.15 " + "Service Charge: Below $500 --- charge $5.00 " + "Total Service Charge: $" + dollar.format(ca.getServiceCharge()) ); firstTime++; } JOptionPane.showMessageDialog(null,"Transaction: Check in Amount of $" + transactionAmount + " " +"Current Balance: $" + dollar.format(ca.getBalance()) + " "+"Service Charge: Check --- charge $0.15 " + "Total Service Charge: $" + dollar.format(ca.getServiceCharge()) ); } else { JOptionPane.showMessageDialog(null,"Transaction: Check in Amount of $" + transactionAmount + " " + "Current Balance: $" + dollar.format(ca.getBalance()) + " "+"Service Charge: Check --- charge $0.15 " + "Service Charge: None " + "Total Service Charge: $" + dollar.format(ca.getServiceCharge()) ); } if(ca.getBalance()<0) { ca.setServiceCharge(10.00); JOptionPane.showMessageDialog(null, "Your balance is under $0."); } if(ca.getBalance()<50) { JOptionPane.showMessageDialog(null, "Your balance is under $50."); } return transAmt; } public static double processDeposit(double transAmt) { ca.setBalance(transAmt, 2); ca.setServiceCharge(0.10); if(ca.getBalance()<500) { if(firstTime==0) { ca.setServiceCharge(5.00); JOptionPane.showMessageDialog(null,"Transaction Amount: Deposit in Amount of " + transactionAmount + " " +"Current Balance: " + dollar.format(ca.getBalance()) + " "+"Service Charge: Deposit --- charge $0.10 " + "Service Charge: Below $500 --- charge $5.00 " + "Total Service Charge: " + dollar.format(ca.getServiceCharge())); } JOptionPane.showMessageDialog(null,"Transaction Amount: Deposit in Amount of " + transactionAmount + " " +"Current Balance: " + dollar.format(ca.getBalance()) + " "+"Service Charge: Deposit --- charge $0.10 " + "Total Service Charge: " + dollar.format(ca.getServiceCharge())); } else { JOptionPane.showMessageDialog(null,"Transaction Amount: Deposit in Amount of " + transactionAmount + " " +"Current Balance: " + dollar.format(ca.getBalance()) + " "+"Service Charge: Deposit --- charge $0.10 " + "Service Charge: None " + "Total Service Charge: " + dollar.format(ca.getServiceCharge())); } if(ca.getBalance()<0) { ca.setServiceCharge(10.00); JOptionPane.showMessageDialog(null, "Your balance is under $0."); } if(ca.getBalance()<50) { JOptionPane.showMessageDialog(null, "Your balance is under $50."); } return transAmt; } } --------------------
CheckingAccount.java ------------------- package accounting;
/** * * @author Natnael Cherenet */ import java.util.ArrayList;
public class CheckingAccount { private double balance; private double totalServiceCharge; public ArrayList
Transaction.Java ---------- package accounting;
/** * * @author Ares */ 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; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
