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...
1) add toString method to BankAccount and SavingsAccount classes 2) Override the withdraw() in SavingsAccount so...
1) add toString method to BankAccount and SavingsAccount classes 2) Override the withdraw() in SavingsAccount so that it will not withdraw more money than is currently in the account. 3) Provide constructors for SavingsAccount 4) Add this feature to SavingsAccount: If you withdraw more than 3 times you are charged $10 fee and the fee is immediately withdrawn from your account.once a fee is deducted you get another 3 free withdrawals. 5) Implement the Comparable Interface for SavingsAccount based on...
Class 1: Account.java Variables: 1. accountNumber (public) 2. accountName (public) 3. balance (private) In Account.java Functions:...
Class 1: Account.java Variables: 1. accountNumber (public) 2. accountName (public) 3. balance (private) In Account.java Functions: 1. Fully parametrized Constructor (to initialize class variables) 2. Getter (getBalance()) and Setter (setBalance()) for the float balance, must be greater than zero. In Account.java Methods: checkBalance( ) to print CURRENT BALANCE. deposit(int added_amount) should add add_amount to balance withdraw(int withdraw_amount) should deduct withdraw_amount balance display( ) will print all the information (account number, name, balance). Class 2: AccountTest.java Create an object account1 and...
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...
Create a program in java using if statements Suppose the WIFI of a client is not...
Create a program in java using if statements Suppose the WIFI of a client is not working and you were assigned to troubleshoot it. For your efforts, suppose you will be paid $20 for every action you take to try to fix it (regardless if the action taken fixes the problem or not). You will also need to ask the customer for a $10 deposit before you start your work. At the end of the troubleshooting process, the client will...
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...
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...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with a Program class and write the following two methods (headers provided) as described below: - A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...