Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

------------------------------------------------ import static java.lang.Math.abs; /** create a class called BankAccount */ abstract class BankAccount { private double balance; private Customer accountHolder; /** this constructor will

image text in transcribed

------------------------------------------------

import static java.lang.Math.abs; /** create a class called BankAccount */ abstract class BankAccount { private double balance; private Customer accountHolder;

/** this constructor will be invoked when no argument given @param none no argument @return nothing */ public BankAccount() { }

/** when creating a new object, this constructor initializes accountHolder and balance @param accountHolder initializes accountHolder @param startBalance initializes balance @return nothing */ public BankAccount(Customer accountHolder, double startBalance) { this.accountHolder = new Customer(accountHolder); this.balance = startBalance; } /** when creating a new object, this constructor initializes balance @param startBalance initializes balance @return nothing */ public BankAccount(double startBalance) { this.balance = startBalance; this.accountHolder = new Customer("", 0); }

/** using this method can access balance @param none method takes no argument @return balance */ public double getBalance() { return this.balance; } /** using this method can add balance @param amount amount of deposit @return nothing */ public void deposit(double amount) { if ((amount > 0) && (amount

/** using this method can decrease balance @param amount amount of withdraw @return nothing */ public void withdraw(double amount) { if ((amount

} } /** using this method can transfer money from BankAccount to account @param amount amount of withdraw and deposit @param toAccount another account @return nothing */ public void transfer(double amount, BankAccount toAccount) { double temp = this.balance; double delta = 0.000001;

this.withdraw(amount); if ((this.balance = temp - delta)) { return; } else { toAccount.deposit(amount); } }

/** using this method can update balance @param amount amount of balance @return nothing */ protected void setBalance(double amount) { this.balance = amount; }

/** using this method can access customer @param none @return clone */ public Customer getCustomer() { Customer clone = new Customer(this.accountHolder.getName(), this.accountHolder.getID()); return clone; } protected abstract double getMonthlyFeesAndInterest(); public void monthEndUpdate(){ setBalance(balance + getMonthlyFeesAndInterest()); }

}

------------------------------------------------

import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.scene.text.Font; import javafx.scene.layout.VBox; import javafx.scene.layout.HBox; import java.text.DecimalFormat; import javafx.event.ActionEvent; import javafx.event.EventHandler; /** class for a banking interface application */ public class BankApplication extends Application {

// Create instances of Customer and SavingsAccount private Customer customer = new Customer("Bob Dylan", 123456); private SavingsAccount s = new SavingsAccount(customer, 150.00);

public static void main(String[] args) { launch(args); } // end main

@Override public void start(Stage primaryStage) throws Exception {

// Create VBox for vertical ordering of Labels and Text Fields VBox root = new VBox(); root.setSpacing(8); // Set vertical spacing between elements in the VBox

// Declare Labels and Text fields Label customerNameLabel, customerIDLabel, balanceLabel; TextField depositTextField, withdrawTextField; Button excButton = new Button("Execute");

// Assign Labels customerNameLabel = new Label("Customer name: " + customer.getName()); customerIDLabel = new Label("Account ID: " + customer.getID()); // Display balance with 2 decimal places DecimalFormat df = new DecimalFormat("#.00"); String balancef = df.format(s.getBalance()); balanceLabel = new Label("Current balance: $" + balancef);

// Set Label Text font and size customerNameLabel.setFont(Font.font("Times New Roman", 16)); customerIDLabel.setFont(Font.font("TImes New Roman", 16)); balanceLabel.setFont(Font.font("TImes New Roman", 16));

// Assign Text fields. // depositTextField will be highlighted initially depositTextField = new TextField("Amt to deposit"); withdrawTextField = new TextField(); withdrawTextField.setPromptText("Amt to withdraw");

//Create an HBox for the TextFields to align horizontally HBox textGroup = new HBox(); // Set horizontal spacing between the textFields textGroup.setSpacing(5);

// Add Text Fields to HBox and set width depositTextField.setPrefWidth(135); textGroup.getChildren().add(depositTextField); withdrawTextField.setPrefWidth(135); textGroup.getChildren().add(withdrawTextField);

// Set the event handler when the execute button is clicked excButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) {

try { // Attempt to convert text to a double and deposit value double deposit = Double.parseDouble(depositTextField.getText()); s.deposit(deposit); } catch (NumberFormatException e) { } try { // Attempt to convert text to a double and withdraw value double withdraw = Double.parseDouble(withdrawTextField.getText()); s.withdraw(withdraw); } catch (NumberFormatException e) { }

// Display balance with 2 decimal places DecimalFormat df = new DecimalFormat("#.00"); String balancef = df.format(s.getBalance()); balanceLabel.setText("Current balance: $" + balancef);

// Reset TextField text // No textField will be highlighted after first use of execute depositTextField.clear(); depositTextField.setPromptText("Amt to deposit."); withdrawTextField.clear(); withdrawTextField.setPromptText("Amt to withdraw");

} // end handle } ); // end EventHandler

// Add Labels and HBox containing Text Fields to VBox Pane root.getChildren().add(customerNameLabel); root.getChildren().add(customerIDLabel); root.getChildren().add(textGroup); root.getChildren().add(excButton); root.getChildren().add(balanceLabel);

// Display Graphics Scene scene = new Scene(root, 350, 200); primaryStage.setTitle("Bank Application"); primaryStage.setScene(scene); primaryStage.show();

} // end start

} // end BankApplication

---------------------------------------------------------------------------

import static java.lang.Math.abs; /** Define a new class ChequingAccount, which is a subclass of BankAccount. */ public class ChequingAccount extends BankAccount {

private double overdraftFee; private double overdraftAmount;

/** When creating an new object,this constructor initializes the transactionFee using the argument. @param transactionFee the expenses incurred in the course of doing things @return this method does not return anything */ public ChequingAccount(double transactionFee) { this.overdraftFee = transactionFee; }

/** When creating an new object,this constructor initializes the customer, startBalance and transactionFee using the arguments. @param accountHolder an account Holder @param startBalance Initial funding @param transactionFee the expenses incurred in the course of doing things @return this method does not return anything */ public ChequingAccount(Customer accountHolder, double startBalance, double transactionFee) { super(accountHolder, startBalance); this.setOverdraftFee(transactionFee); }

/** Using this method can access the OverdraftFee . @param none this method takes no argument @return overdraftFee */ public double getOverdraftFee() { return this.overdraftFee; }

/** Using this method can update the OverdraftFee. @param fee money @return this method doesn't return anything */ public void setOverdraftFee(double fee) { this.overdraftFee = fee; }

/** Using this method can access the overdraftAmount. @param none this method takes no argument @return overdraftAmount */ public double getOverdraftAmount() { return this.overdraftAmount; }

/** Using this method can update the overdraftAmount. @param overdraft the amount that is allowed to overdraft @return this method doesn't return anything */ public void setOverdraftAmount(double overdraft) { if (abs(overdraft) = -overdraft) { overdraftAmount = overdraft; } } }

/** Reduce the amount using this method @param amount amount of withdraw @return this method does not return anything */ public void withdraw(double amount) {

if (amount > this.getBalance()) { if (amount

if (amount 0.0) return 0.0; return getBalance()*0.2; }

}

--------------------------------------------------

/** Class for customer data?name and id. */ public final class Customer {

private String name; private int id = 0;

/** this constructor will be invoked when no argument given @param none no argument @return nothing */ public Customer() {

}

/** When creating an new object,this constructor initializes the name and customer's ID using the arguments @param name initializes name @param id initializes id @return this method doesn't return anything */ public Customer(String name, int id) { this.name = new String(name); this.id = id; }

/** When creating an new object,initializing name and customer's ID copying the data of other customer object @param oldCustomer a variable that represents the account owner, including information of name and ID @return this method doesn't return anything. */ public Customer(Customer oldCustomer) { name = new String(oldCustomer.getName()); id = oldCustomer.getID(); }

/** Using this method can access the customer's name. @param none this method takes no argument @return name */ public String getName() { return new String(name); }

/** Using this method can access the id. @param none this method takes no argument @return customer's ID */ public int getID() { return id; }

/** Using this method can get the information of name and id. @param none this method takes no argument @return the information of name and id */ public String toString() { return new String("Name of Customer: " + name + " CustomerID: " + id + " "); } /*Answer:It's because that the accountHolder instance variable is private, and there's no setter method in BankAccount to change it. In addition, the class Customer is immutable, its two instance variables are private and there's no setter methods(setID(...) and setName(...)) for them. Therefore, it is not possible to use method getCustomer( ) then use setter moethods for example: setID(...) to change the value of variable because there's no setter methods. */ }

--------------------------------------------

/** Define a new class SavingsAccount, which is a subclass of BankAccount. */ public class SavingsAccount extends BankAccount {

private static double annualInterestRate;

/** When creating an new object,if no arguments provided, using this constructor to initialize it. @param none this method takes no argument @return this method does not return anything */ public SavingsAccount() { }

/** When creating an new object,this constructor initializes the accountHolder,balance and annualInterestRate using the arguments @param accountHolder initializes the accountHolder @param startBalance initializes the balance @param annualInterestRate initializes the annualInterestRate @return this method does not return anything */ public SavingsAccount(Customer accountHolder, double startBalance, double annualInterestRate) { super(accountHolder, startBalance); this.setAnnualInterestRate(annualInterestRate); } /** When creating an new object,this constructor initializes the accountHolder and balance @param accountHolder initializes the accountHolder @param startBalance initializes the balance @return nothing */ public SavingsAccount(Customer accountHolder, double startBalance){ super(accountHolder, startBalance); }

/** Using this method can access the annualInterestRate. @param none this method takes no argument @return deposit rate of one year */ public double getAnnualInterestRate() { return annualInterestRate; }

/** Using this method can update the annualInterestRate. @param annualInterestRate a new one year deposit rate @return this method does not return anything */ public static void setAnnualInterestRate(double interestRate) { if ((interestRate = 0)) { annualInterestRate = interestRate; } }

/** can use this method to deposit the monthly interest to the account @param none this method takes no argument @return this method does not return anything */ public void depositMonthlyInterest() { double monthlyInterest = ((annualInterestRate/100) * (this.getBalance())) / 12.0; this.deposit(monthlyInterest); } /** this method computes monthly fees and monthly interest @param none takes no argument @return the outcome depending on 3 cases. */ protected double getMonthlyFeesAndInterest(){ if (getBalance() > 0.0 && getBalance() >= 1000.0) return getBalance()*(getAnnualInterestRate()/100.0/12.0); else if (getBalance() > 0.0) return getBalance()*(getAnnualInterestRate()/100.0/12.0) - 5.0; return getBalance()*0.2; }

}

-------------------------------------------------------

Note: class BankApplication is class GUI

Requirements To be able to work on this assignment, you will need a functional version of all previous team assignments You'll need BankAccount, ChequingAccount, SavingsAccount, Customer and the GUI class you've created Below are the tasks for this assignment: 1. When the application starts, it will get the account information from a text file. If there is no file with account information, create a new account instead. When creating a new account a. Ask the user if they wish to create a savings account or a chequing account. b. Ask the user for the customer name. Randomly generate a customer ID between 1000 and c. Update your graphical user interface to get this information from the user. 2. When the application closes, the text file should have the updated account information. (Which will be used when the BankApp is started again). Make sure to write sufficient information to the text file such that you can recreate the BankAccount when the app is started again. . Validate the amount to deposit/withdraw. If the amount is not a number or it is not a valid number, give a descriptive error message (in the GUI) Requirements To be able to work on this assignment, you will need a functional version of all previous team assignments You'll need BankAccount, ChequingAccount, SavingsAccount, Customer and the GUI class you've created Below are the tasks for this assignment: 1. When the application starts, it will get the account information from a text file. If there is no file with account information, create a new account instead. When creating a new account a. Ask the user if they wish to create a savings account or a chequing account. b. Ask the user for the customer name. Randomly generate a customer ID between 1000 and c. Update your graphical user interface to get this information from the user. 2. When the application closes, the text file should have the updated account information. (Which will be used when the BankApp is started again). Make sure to write sufficient information to the text file such that you can recreate the BankAccount when the app is started again. . Validate the amount to deposit/withdraw. If the amount is not a number or it is not a valid number, give a descriptive error message (in the GUI)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

(f) What type of factorial design it is?

Answered: 1 week ago