Question

Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file....

Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file. Both files must be in the same directory to compile.

Display all dollar amounts using the DecimalFormat class.

  1. Create an account
    • Ask the user for the type of account, the bank account number, the amount that they will deposit to start the account. Set interest earned to 0.
    • Print the account information using an implicit or explicit call to toString
  2. Update an account
    • Use the mutator methods to test this functionality
    • Print the bank account variable information using an implicit or explicit call to toString after updating
  3. Deposit to an existing account
    • Ask the user how much they want to deposit
    • Call the deposit method
    • Print the bank account variable information using an implicit or explicit call to toString
    • Make sure the balance is correct with valid and invalid values
  4. Withdraw from an existing account
    • Ask the user how much they want to withdraw
    • Call the withdraw method
    • Print the bank account variable information using an implicit or explicit call to toString
    • Make sure the balance is correct with valid and invalid values
  5. Update interest on an existing account
    • Call the method to add interest to the account
    • Print the bank account variable information using an implicit or explicit call to toString
    • Make sure that the balance has been updated
  6. Compare the current account with another account
    • Create another account with the same information as the current account using the accessor methods to get the data from the current account
    • Call the equals method to verify that the data in each is the same
    • Print a message indicating that the two accounts are the same and print both accounts using the toString method
  7. Exit
  • Thank the user and say goodbye


1. Use enum to give the types of bank accounts that are available: Checking, Savings, Money   

Market, IRA, Certificate of Deposit.

2. For the mutators, accept a string passed from the client for the type of bank account and convert

it into an enum value.

3. For the accessors, convert the enum value to a string before returning the value to the client.

Homework Answers

Answer #1

BankAccount.java

public class BankAccount {
enum AccountType
{
Checking,
Savings,
MoneyMarket,
IRA,
CertificateOfDeposit;
}
private AccountType type;
private int accountNumber;
private double balance;
private double interestRate;
  
public BankAccount()
{
this.type = AccountType.Savings;
this.accountNumber = 0;
this.balance = 0.0;
this.interestRate = 0.0;
}

public AccountType getType() {
return type;
}

public void setType(String type) {
if(type.equalsIgnoreCase("Checking"))
this.type = AccountType.Checking;
else if(type.equalsIgnoreCase("Savings"))
this.type = AccountType.Savings;
else if(type.equalsIgnoreCase("Money Market"))
this.type = AccountType.MoneyMarket;
if(type.equalsIgnoreCase("IRA"))
this.type = AccountType.IRA;
if(type.equalsIgnoreCase("Certificate of Deposit"))
this.type = AccountType.CertificateOfDeposit;
}

public int getAccountNumber() {
return accountNumber;
}

public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}

public double getBalance() {
return balance;
}

public void setBalance(double balance) {
this.balance = balance;
}

public double getInterestRate() {
return interestRate;
}

public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
  
public double getInterest()
{
return((getBalance() * getInterestRate()) / 100);
}
  
public void deposit(double amt)
{
if(amt < 0)
System.out.println("Amount cannot be negative!");
else
setBalance(getBalance() + amt);
}
  
public void withdraw(double amt)
{
if(amt > getBalance())
System.out.println("Insufficient funds!");
else
setBalance(getBalance() - amt);
}
  
public void applyInterest()
{
deposit(getInterest());
}
  
public String getAccountTypeString()
{
if(this.type == AccountType.CertificateOfDeposit)
return "Certificate of Deposit";
else if(this.type == AccountType.Checking)
return "Checking";
else if(this.type == AccountType.IRA)
return "IRA";
else if(this.type == AccountType.MoneyMarket)
return "Money Market";
else if(this.type == AccountType.Savings)
return "Savings";
else
return "Savings";
}
  
@Override
public String toString()
{
return("Account Number: " + getAccountNumber() + "\n"
+ "Account Type: " + getAccountTypeString() + "\n"
+ "Interest Rate: " + String.format("%.2f", getInterestRate()) + "%\n"
+ "Balance: $" + String.format("%,.2f", getBalance()));
}
  
@Override
public boolean equals(Object o)
{
if(o instanceof BankAccount)
{
return(getAccountNumber() == ((BankAccount) o).getAccountNumber() &&
getAccountTypeString().equalsIgnoreCase(((BankAccount) o).getAccountTypeString()) &&
getInterestRate() == ((BankAccount) o).getInterestRate() &&
getBalance() == ((BankAccount) o).getBalance());
}
else
return false;
}
}

BankAccountClient.java (Main class)

import java.util.Scanner;

public class BankAccountClient {
  
public static void main(String[] args) {
BankAccount account = new BankAccount();
Scanner sc = new Scanner(System.in);
System.out.print("Enter the type of account:\n"
+ "1. Savings\n"
+ "2. Checking\n"
+ "3. Money Market\n"
+ "4. IRA\n"
+ "5. Certificate of Deposit\n"
+ "Your choice: ");
int choice = Integer.parseInt(sc.nextLine().trim());
String type = "";
while(choice < 1 || choice > 5)
{
System.out.println("Invalid selection!");
System.out.print("Enter the type of account:\n"
+ "1. Savings\n"
+ "2. Checking\n"
+ "3. Money Market\n"
+ "4. IRA\n"
+ "5. Cerrtificate of Deposit\n"
+ "Your choice: ");
choice = Integer.parseInt(sc.nextLine().trim());
}
switch(choice)
{
case 1:
type = "Savings";
break;
case 2:
type = "Checking";
break;
case 3:
type = "Money Market";
break;
case 4:
type = "IRA";
break;
case 5:
type = "Certificate of Deposit";
break;
}
  
System.out.print("Enter the account number: ");
int accountNumber = Integer.parseInt(sc.nextLine().trim());
System.out.print("Enter the initital deposit amount: $");
double amount = Double.parseDouble(sc.nextLine().trim());
double interestRate = 0.0;
account.setType(type);
account.setAccountNumber(accountNumber);
account.setBalance(amount);
account.setInterestRate(interestRate);
System.out.println("Initial account information..\n" + account);
  
System.out.println("\nUpdating account balance to 5000..");
account.setBalance(5000);
System.out.println(account);
  
System.out.print("\nEnter the amount of deposit: $");
double depositAmt = Double.parseDouble(sc.nextLine().trim());
account.deposit(depositAmt);
System.out.println(account);
  
System.out.print("\nEnter the amount to withdraw: $");
double withdrawAmt = Double.parseDouble(sc.nextLine().trim());
account.withdraw(withdrawAmt);
System.out.println(account);
  
System.out.println("\nUpdating interest rate to 7.85%..");
account.setInterestRate(7.85);
account.applyInterest();
System.out.println(account);
  
System.out.println("\nCreating another account with the information of the above account and comparing them..");
BankAccount dup = new BankAccount();
dup.setAccountNumber(account.getAccountNumber());
dup.setType(type);
dup.setInterestRate(account.getInterestRate());
dup.setBalance(account.getBalance());
System.out.println("Are the two accounts same? " + account.equals(dup));
}
}

********************************************************** SCREENSHOT ******************************************************

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private data fields to store the account holder's name and the account balance A constructor with 0 arguments A constructor with 1 argument (account holder's name) A constructor with 2 arguments(account holder's name and account balance) Public properties for the account holder's name and the account balance. Do not use auto-implemented properties. A method to increase the balance (deposit) A method to decrease the balance...
Create a Software Application for XYZ Bank that allows its members to access their bank account...
Create a Software Application for XYZ Bank that allows its members to access their bank account information through an “ATM like” interface. The Menu Options should include: checking the account balance, debiting the account and crediting the account, along with an option to exit the program. Create an Account Class to represent the customers’ bank accounts. Include a data member of type float to represent the account balance. Provide a constructor that receives an initial balance and uses it to...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain...
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain account numbers (10 digits) along with the account type (L:Loan and S:Savings) and their current balance. The second file (transactions.txt) will contain transactions on the accounts. It will specifically include the account number, an indication if it is a withdrawal/deposit and an amount. Both files will be pipe delimited (|) and their format will be the following: accounts.txt : File with bank account info...
6. Your client prints a Balance Sheet report as of today’s date and notices that the...
6. Your client prints a Balance Sheet report as of today’s date and notices that the checking account balance in the register does not match the balance shown in today's balance sheet. What might cause this? A. The bank account has never been reconciled B. The Balance Sheet was prepared using accrual basis C. There is a balance in the Undeposited Funds account D. The client entered bank transactions dated past the date on the Balance Sheet report 7. Which...
For this assignment, create an html page that has a login form. The form should have...
For this assignment, create an html page that has a login form. The form should have 3 input elements -- 1. This should have a type text for the user to enter UserName 2. This should have a type password (like text except cannot see the text that is typed in), for the user to enter password. 3. Submit button (type submit, as we did in class on 2/6). The form method should be set to POST and the action...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT