Question

In: Computer Science

Write in Java the following: A.  A bank account class that has three protected attributes: account number...

Write in Java the following:

A.  A bank account class that has three protected attributes: account number (string), customer name (string), and balance (float). The class also has a parameterized constructor and a method public void withDraw (float amount) which subtracts the amount provided as a parameter from the balance.

B. A saving account class that is a child class of the bank account class with a private attribute: penality rate (float). This class also has a parameterized constructor and a method public void withDraw (float amount) which decreases the available balance based on the following formula:

balance = balance - amount * (1+penality rate ).

Solutions

Expert Solution

Code:

import java.util.*;

class BankAccount {
    protected String accountNumber;
    protected String customerName;
    protected float balance;

    public BankAccount(String accountNumber, String customerName, float balance) {
        this.accountNumber = accountNumber;
        this.customerName = customerName;
        this.balance = balance;
    }

    public void withdraw(float amount) {
        this.balance = this.balance - amount;
    }
}

class SavingAccount extends BankAccount {

    private float penaltyRate;

    public SavingAccount(String accountNumber, String customerName, float balance, float penaltyRate) {
        super(accountNumber, customerName, balance);//calling parent class constructor
        this.penaltyRate = penaltyRate;
    }

    public void withdraw(float amount) {
        super.balance = super.balance - amount * (1 + penaltyRate / (float) 100.0);
    }

}

class Main {

    public static void main(String[] args) {
        SavingAccount s = new SavingAccount("48499920dx03d", "Tom Michaels", 22000, 5);

       //displaying balance information
        System.out.println("Current balance : "+s.balance);
        //withdrawing amount
        s.withdraw(10000);
        System.out.print("Balance after withdrawing 10000 at 5 percent penalty rate : ");
        System.out.println(s.balance);
    }
}



Code screenshot:

output:


Related Solutions

How to write a Java program that has a base class with methods and attributes, subclasses...
How to write a Java program that has a base class with methods and attributes, subclasses with methods and attributes. Please use any example you'd like.
Write a Java program for a simple bank account. You shall define a Customer class: A...
Write a Java program for a simple bank account. You shall define a Customer class: A customer has a first name, last name, and social security number. The social security number is a String variable and must comply with this format: xxx-xx-xxxx where 'x' is a digit between 0-9. If a customer is supplied with an invalid SSN, a message must be printed stating SSN of the customer is invalid; however, the account still is created. You shall define a...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and deposit. Test the methods in the main function.
13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number...
13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. This class provides the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. b. The class  checkingAccount from the class bankAccount (designed in part a). This class inherits members to store the account number and the balance from the base class. A customer...
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...
Write a class encapsulating a board game. A board game has the following additional attributes: the...
Write a class encapsulating a board game. A board game has the following additional attributes: the number of players and whether the game can end in a tie. Code the constructor and the toString method of the new class. You also need to include a client class(with the main method) to test your code. code in Python
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT