Hi, I need help fixing this Java Code with one GUI (BankingApplication) that con
ID: 662663 • Letter: H
Question
Hi, I need help fixing this Java Code with one GUI (BankingApplication) that contains 3 classes (Account, Checking, and Savings) I don't know what's the problem. We are using Eclipse to run our Java Program. The error message is line 468 in the BankingApplication class, line 15 in the checking class, and line 16 in the Savings class. Here is my code in order (Banking, Account, Checking, and Savings). Here are the instructions of what Im suppose to do. Thanks
CISP21
Programming in Java
Assignment 8
For this lab assignment, you will be completing your next project. Your project must be created in Eclipse editor and meet all of the requirements listed.
Project Description
The Friendly Neighborhood Bank needs to maintain information on its bank accounts. The bank allows two types of accounts
Explanation / Answer
Changes BankApplication changes are displayed make those changes and Acoount changes are displayed in bold .
Above changes a comment is witten as changes.In Checking and Saving add unimplemented methods Account.setDeposit() and
Account.getFee() as they inherited abstract class Account.
BankingApplication.java:
import java.awt.event.*; //for ActionListener
import javax.swing.*; //for swing components
import java.awt.*; //for Font
import java.text.*; //for DecimalFormat class
public class BankingApplication extends JFrame
implements ActionListener
{
//added components for first panel
//Array for the combo box
String choiceString [] = {"Create Account","Withdraw or Deposit","Show all Accounts"};
JLabel companyLabel = new JLabel (" Friendly Neighborhood Bank ");
JLabel selectLabel = new JLabel ("Please Select an Action: ");
JComboBox selectComboBox = new JComboBox(choiceString);
JButton goButton = new JButton("Go");
//added components for second panel
JLabel companyLabel2 = new JLabel (" Friendly Neighborhood Bank ");
JLabel firstNameLabel = new JLabel (" First name ");
JTextField firstNameTextField = new JTextField(10);
JLabel lastNameLabel = new JLabel (" Last name ");
JTextField lastNameTextField = new JTextField(10);
JLabel newPinLabel = new JLabel (" PIN ");
JTextField newPinTextField = new JTextField(10);
JRadioButton checkingRadioButton = new JRadioButton(" Checking ");
JRadioButton savingRadioButton = new JRadioButton(" Savings ");
JRadioButton invisibleRadioButton2 = new JRadioButton("");
JButton processNewAccountButton = new JButton("Process");
JButton backFromNewAccountButton = new JButton("Back");
JTextArea accountOutputTextArea = new JTextArea(10,15);
ButtonGroup accountButtonGroup = new ButtonGroup();
//added components for third panel
JLabel companyLabel3 = new JLabel (" Friendly Neighborhood Bank ");
JRadioButton withdrawRadioButton = new JRadioButton(" Withdraw ");
JRadioButton depositRadioButton = new JRadioButton(" Deposit ");
JRadioButton invisibleRadioButton = new JRadioButton("");
ButtonGroup transactionButtonGroup = new ButtonGroup();
JRadioButton checkingRadioButton2 = new JRadioButton(" Checking ");
JRadioButton savingRadioButton2 = new JRadioButton(" Savings ");
JRadioButton invisibleRadioButton3 = new JRadioButton("");
JLabel confirmPinLabel = new JLabel(" PIN: ");
JTextField confirmPinTextField = new JTextField(25);
JLabel amountLabel = new JLabel(" Enter amount: ");
JTextField amountTextField = new JTextField(25);
JButton processTransactionButton = new JButton("Process");
JButton backFromTransactionButton = new JButton("Back");
JTextArea transactionOutputTextArea = new JTextArea(10,15);
//Added JTextArea for displaying all accounts
JTextArea displayAllTextArea = new JTextArea(10, 42);
JPanel mainPanel = new JPanel();
JPanel accountPanel = new JPanel();
JPanel transactionPanel = new JPanel();
Font taFont = new Font("Courier", Font.PLAIN, 12);
Font companyFont = new Font ("Sans Serif", Font.BOLD, 20);
Font programmerNameFont = new Font ("Sans Serif", Font.ITALIC, 10);
// instance objects and variables
Account [] myAccount = new Account[10];
int lastAccountInteger = -1;
final int MAX_ACCOUNTS_INTEGER = 9;
String typeString;
//double totalBalanceDouble;
// the main method will create an object of itself and
//set the default close operation
public static void main(String[] args)
{
BankingApplication myApplication = new BankingApplication();
myApplication.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//constructor
//call the methods to add components to the multiple panels
//also sets size and visibility
public BankingApplication()
{
designMainPanel();
designAccountPanel();
designTransactionPanel();
addListeners();
add(mainPanel);
setSize(400,200);
setVisible(true);
}
//this method will create the main panel
public void designMainPanel()
{
//add components to the mainPanel
companyLabel.setFont(companyFont);
mainPanel.add(companyLabel);
mainPanel.add(selectLabel);
mainPanel.add(selectComboBox);
mainPanel.add(goButton);
//Changes
JLabel programmerNameLabel= new JLabel();
programmerNameLabel.setFont(programmerNameFont);
mainPanel.add(programmerNameLabel);
}
//this method creates the account panel
public void designAccountPanel()
{
//add components to the adminPanel
accountPanel.setLayout(new FlowLayout(FlowLayout.CENTER,60,15));
companyLabel2.setFont(companyFont);
accountButtonGroup.add(checkingRadioButton);
accountButtonGroup.add(savingRadioButton);
accountButtonGroup.add(invisibleRadioButton);
accountPanel.add(companyLabel2);
accountPanel.add(firstNameLabel);
accountPanel.add(firstNameTextField);
accountPanel.add(lastNameLabel);
accountPanel.add(lastNameTextField);
accountPanel.add(newPinLabel);
accountPanel.add(newPinTextField);
accountPanel.add(checkingRadioButton);
accountPanel.add(savingRadioButton);
accountPanel.add(processNewAccountButton);
accountPanel.add(backFromNewAccountButton);
accountPanel.add(accountOutputTextArea);
String formattedTitleString = String.format("%-20s%-6s%10s%n",
"Name","PIN","Balance");
accountOutputTextArea.setFont(taFont);
accountOutputTextArea.setText(formattedTitleString);
}
//this method creates the transaction panel
public void designTransactionPanel()
{
//add the container group to the radio buttons
transactionButtonGroup.add(depositRadioButton);
transactionButtonGroup.add(withdrawRadioButton);
transactionButtonGroup.add(invisibleRadioButton);
companyLabel3.setFont(companyFont);
transactionPanel.add(companyLabel3);
transactionPanel.add(depositRadioButton);
transactionPanel.add(withdrawRadioButton);
transactionPanel.add(confirmPinLabel);
transactionPanel.add(confirmPinTextField);
transactionPanel.add(amountLabel);
transactionPanel.add(amountTextField);
transactionPanel.add(processTransactionButton);
transactionPanel.add(backFromTransactionButton);
transactionPanel.add(transactionOutputTextArea);
String formattedTitleString = String.format("%-20s%-6s%-12s%-10s%10s%n",
"Name","PIN","Trans Type", "Trans Amt", "Balance" );
transactionOutputTextArea.setFont(taFont);
transactionOutputTextArea.setText(formattedTitleString);
}
//this method helps find accounts match with their pin number
public int findAccount(String pinNumString)
{
int searchIndex = 10;
boolean foundAcct = false;
int currentIndex = 0;
while (!foundAcct && currentIndex <= lastAccountInteger)
{
if(pinNumString.equalsIgnoreCase(myAccount[currentIndex].getPinNumberString()))
{
searchIndex = currentIndex;
foundAcct = true;
}
currentIndex ++;
}
return searchIndex;
}
//this method puts action listeners on all the desired buttons
public void addListeners()
{
//add the listeners to the respective components
selectComboBox.addActionListener(this);
goButton.addActionListener(this);
processNewAccountButton.addActionListener(this);
backFromNewAccountButton.addActionListener(this);
processTransactionButton.addActionListener(this);
backFromTransactionButton.addActionListener(this);
}
//this method assigns the actions and methods to the correct button
public void actionPerformed(ActionEvent evt)
{
//buttons fire this event
Object sourceObject = evt.getSource();
if (sourceObject == goButton)
{
if(selectComboBox.getSelectedIndex() == 0) //Add an account option
{
remove(mainPanel);
invisibleRadioButton.setSelected(true);
remove(transactionPanel);
add(accountPanel);
setSize(320,600);
setVisible(true);
}
else if (selectComboBox.getSelectedIndex() == 1) //Transaction option
{
remove(mainPanel);
invisibleRadioButton.setSelected(true);
remove(accountPanel);
add(transactionPanel);
setSize(490,400);
setVisible(true);
}
else if(selectComboBox.getSelectedIndex() == 2) //Display all transactions option
{
displayAllAccountInfo();
}
else
JOptionPane.showMessageDialog(null, "Please make a selection in the combo box before pressing Go.");
}
if(sourceObject == processNewAccountButton)
{
if(validationNewAccountFields())
processNewAccount();
if(validationNewAccountFields())
processNewAccount();
else
JOptionPane.showMessageDialog(null, "Please select either Checkings or Savings");
}
else if(sourceObject == processTransactionButton)
{
if(validationTransRadioButtons())
processTransaction();
else
JOptionPane.showMessageDialog(null, "Please select either withdraw or deposit");
}
else if(sourceObject == backFromNewAccountButton)
{
remove(accountPanel);
invisibleRadioButton.setSelected(true);
remove(transactionPanel);
selectComboBox.setSelectedIndex(-1);
add(mainPanel);
setSize(400,200);
setVisible(true);
}
else if(sourceObject == backFromTransactionButton)
{
remove(transactionPanel);
remove(accountPanel);
selectComboBox.setSelectedIndex(-1);
add(mainPanel);
setSize(400,200);
setVisible(true);
}
}//end of actionPerformed method
//validates if something has been entered into the three text fields
public boolean validationNewAccountFields()
{
boolean validationBoolean = false;
if(!(firstNameTextField.getText()).equals(""))
{
if(!(lastNameTextField.getText()).equals(""))
{
if(!(newPinTextField.getText()).equals(""))
{
validationBoolean = true;
}
else
{
JOptionPane.showMessageDialog(null, "Please enter a PIN");
newPinTextField.requestFocus();
validationBoolean = false;
}
}
else
{
JOptionPane.showMessageDialog(null, "Please enter Last Name");
lastNameTextField.requestFocus();
validationBoolean = false;}
}
else
{
JOptionPane.showMessageDialog(null, "Please enter First name");
firstNameTextField.requestFocus();
validationBoolean = false;
}
return validationBoolean;
}
//this method will validate if a radio button was selected
public boolean validationTransRadioButtons()
{
boolean validationBoolean = false;
if(depositRadioButton.isSelected() || withdrawRadioButton.isSelected())
validationBoolean = true;
else
validationBoolean = false;
return validationBoolean;
}
//this method will make a new account
public void processNewAccount()
{
String customerNameString = firstNameTextField.getText();
String customerLastString = lastNameTextField.getText();
String pinString = newPinTextField.getText();
if(findAccount(pinString) == 10)
{
if(checkingRadioButton.isSelected())
{
lastAccountInteger++;
myAccount[lastAccountInteger] = new Checking(customerNameString, customerLastString, pinString);
myAccount[lastAccountInteger].setBalance(100.0);
String formattedNewDisplayString = String.format("%-20s%-6s%10s%n",customerNameString +" " + customerLastString, pinString, myAccount[lastAccountInteger].toString());
accountOutputTextArea.append(formattedNewDisplayString);
}
else if (savingRadioButton.isSelected())
{
lastAccountInteger++;
myAccount[lastAccountInteger] = new Savings(customerNameString, customerLastString, pinString);
myAccount[lastAccountInteger].setBalance(500.0);
String formattedNewDisplayString = String.format("%-20s%-6s%10s%n",customerNameString +" " + customerLastString, pinString, myAccount[lastAccountInteger].toString());
accountOutputTextArea.append(formattedNewDisplayString);
}
else{
JOptionPane.showMessageDialog(null, "Pin already in use");
}
}
}//end of processNewAccount method
//this method checks if the entered pin is correct and then withdraws or deposits depending on the radio button
public void processTransaction()
{
String customerPinString = confirmPinTextField.getText();
Double takeOutDouble = Double.parseDouble(amountTextField.getText());
int tempButton = 0;
try {
if(takeOutDouble >= 0.0)
{
if(depositRadioButton.isSelected())
{
if(checkingRadioButton.isSelected())
{
int customerIndexInt=findAccount(customerPinString);
if(customerIndexInt < 10)
{
if(checkingRadioButton2.isSelected())
{
myAccount[customerIndexInt].deposit(takeOutDouble);
String formattedTransactionDisplayString = String.format("%-20s%-6s%-12s%-10s%10s%n",myAccount[customerIndexInt].getCustomerFirstName() +" " + myAccount[customerIndexInt].getCustomerLastName(),myAccount[customerIndexInt].getPinNumberString(),
"Checking","Deposit",takeOutDouble, myAccount[lastAccountInteger].toString());
transactionOutputTextArea.append(formattedTransactionDisplayString);
}
else if (savingRadioButton2.isSelected())
{
myAccount[customerIndexInt].deposit(takeOutDouble);
String formattedTransactionDisplayString = String.format("%-20s%-6s%-12s%-10s%10s%n",myAccount[customerIndexInt].getCustomerFirstName() +" " + myAccount[customerIndexInt].getCustomerLastName(),myAccount[customerIndexInt].getPinNumberString(),
"Savings","Deposit",takeOutDouble, myAccount[lastAccountInteger].toString());
transactionOutputTextArea.append(formattedTransactionDisplayString);
}
}//end of 2nd if
}//end of first if
else if (takeOutDouble <0.0)
throw new Exception ("Cant be Negative");
}
}
}
//end of try statement
catch(Exception err)
{
JOptionPane.showMessageDialog(null,"Can't be Negative" + err.getMessage());
}//end of catch
//Your process a transaction (deposit or withdrawal) should go here!
try{
if (withdrawRadioButton.isSelected())
{
int customerIndexInt2 = findAccount(customerPinString);
if(customerIndexInt2 < 10)
{
if(checkingRadioButton2.isSelected())
{
if(takeOutDouble >=750)
tempButton = JOptionPane.showConfirmDialog(null,"$2.00 well be charged","Confirm",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(tempButton == JOptionPane.YES_OPTION)
{
String formattedTransactionDisplayString = String.format("%-20s%-6s%-12s%-10s%10s%n",myAccount[customerIndexInt2].getCustomerFirstName() +" " + myAccount[customerIndexInt2].getCustomerLastName(),myAccount[customerIndexInt2].getPinNumberString(),
"Checking","Deposit",takeOutDouble, myAccount[lastAccountInteger].toString());
transactionOutputTextArea.append(formattedTransactionDisplayString);
}
else if (tempButton == JOptionPane.NO_OPTION)
{
String formattedTransactionDisplayString = String.format("%-20s%-6s%-12s%-10s%10s%n",myAccount[customerIndexInt2].getCustomerFirstName() +" " + myAccount[customerIndexInt2].getCustomerLastName(),myAccount[customerIndexInt2].getPinNumberString(),
"Checking","Deposit",takeOutDouble, myAccount[lastAccountInteger].toString());
transactionOutputTextArea.append(formattedTransactionDisplayString);
}
}
//end of checking withdrawal if statement
else if (savingRadioButton2.isSelected())
{
if(takeOutDouble >=2000)
tempButton = JOptionPane.showConfirmDialog(null,"$2.50 well be charged","Confirm",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(tempButton == JOptionPane.YES_OPTION)
{
String formattedTransactionDisplayString = String.format("%-20s%-6s%-12s%-10s%10s%n",myAccount[customerIndexInt2].getCustomerFirstName() +" " + myAccount[customerIndexInt2].getCustomerLastName(),myAccount[customerIndexInt2].getPinNumberString(),
"Checking","Deposit",takeOutDouble, myAccount[lastAccountInteger].toString());
transactionOutputTextArea.append(formattedTransactionDisplayString);
//changes
}
if(takeOutDouble > myAccount[customerIndexInt2].getBalanceDouble())
{
throw new Exception("Cannot Withdrawl Over The Limit");
}
else
{
myAccount[customerIndexInt2].withdraw(takeOutDouble);
String formattedTransactionDisplayString = String.format("%-20s%-6s%-12s%-10s%10s%n",myAccount[customerIndexInt2].getCustomerFirstName() +" " + myAccount[customerIndexInt2].getCustomerLastName(),myAccount[customerIndexInt2].getPinNumberString(),
"Withdraw",takeOutDouble, myAccount[customerIndexInt2].toString());
transactionOutputTextArea.append(formattedTransactionDisplayString);
//changes
}
}
}
}
}
//end of try
catch (Exception out)
{
JOptionPane.showMessageDialog(null,""+ out.getMessage());
}//end of catch
}//end of processTransaction method
//this method shows the account information in a JOption pane
public void displayAllAccountInfo()
{String formattedTextString = String.format("%-20s%-6s%10s%n","Name","PIN","Balance");
accountOutputTextArea.setFont(taFont);
accountOutputTextArea.setText(formattedTextString);
for(int i = 0; i <= lastAccountInteger; i++)
{
String formattedString = String.format("%-20s%-6s%10s%n",myAccount[i].getCustomerFirstName() + " " + myAccount[i].getCustomerLastName(),myAccount[i].getPinNumberString(),myAccount[i].toString());
accountOutputTextArea.append(formattedString);
}
JOptionPane.showMessageDialog(null,accountOutputTextArea);
}//end of displayAllAccountInfo method
}
Account.java:
import java.awt.*;
import java.awt.List;
import java.text.DecimalFormat;
import java.util.*;
import javax.swing.*;
public abstract class Account
{
protected double customerBalanceDouble = 0.0;
//currency format
public final DecimalFormat MONEY = new DecimalFormat("$#0.00");
protected final DecimalFormat Charge = new DecimalFormat("$#0.00");
// private can only be seen in this class
//private variables
protected String customerFirstNameString;
protected String customerLastNameString;
protected String pinNumberString;
protected double chargeFee = 0;
//Constructors
//to set and store account information
public Account()
{
customerFirstNameString = "";
customerLastNameString = "";
pinNumberString = "";
}
//Declare variables
public Account(String firstString, String lastString, String pinString)
{
customerFirstNameString = firstString;
customerLastNameString = lastString;
pinNumberString = pinString;
}
//set method
//this will set balance
public void setBalance(Double balanceDouble)
{
customerBalanceDouble = balanceDouble;
}
//this will set first name
public void setNameString(String firstString)
{
customerFirstNameString = firstString;
}
//this will set last name
public void setLastString(String lastNameString)
{
customerLastNameString = lastNameString;
}
//this will set Pin Number
public void setPinNumberString(String pinString)
{
pinNumberString = pinString;
}
//get method
//get customer first name
public String getCustomerFirstName()
{
return customerFirstNameString;
}
//get customer last name
public String getCustomerLastName()
{
return customerLastNameString;
}
//get pin number
public String getPinNumberString()
{
return pinNumberString;
}
//get customer balance
public Double getBalanceDouble()
{
return customerBalanceDouble;
}
//this will be an abstract
public abstract void setDeposit();
public abstract void setFee();
public abstract double getFee();
//Deposits after $100 automatically added into new account.
public void deposit (double amount)
{
if(amount >=0.0)
customerBalanceDouble += amount;
}
//Method where the withdrawal cannot exceed the bal.
public void withdraw (double amount)
{
if(amount >=0.0 && amount <=customerBalanceDouble)
customerBalanceDouble -= amount;
}
//format customer balance with currency format
public String toString()
{
return (MONEY.format(customerBalanceDouble));
}
public String getCharge()
{
setFee();
getFee();
return (Charge.format(chargeFee));
}
//changes
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.