Account.java
public class Account {
private long number;
private double balance;
public Account(){
number = 0;
balance = 0.0;
}
public Account(long number, double balance) {
this.number = number;
this.balance = balance;
}
public long getNumber() {
return number;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void deposit(double amt)
{
if(amt > 0)
balance += amt;
}
public void withdraw(double amt)
{
if(amt < balance)
balance -= amt;
}
@Override
public String toString() {
return "Account number=" + number + "\nBalance=" + balance;
}
}
SavingsAccount.java
public class SavingsAccount extends Account{
private double apr;
public SavingsAccount() {
super(); // calls the no-arg constructor of Account class
apr = 0.0;
}
public SavingsAccount(long number, double balance, double apr)
{
super(number, balance); // calls the 2-arg constructor of Account
class
this.apr = apr/100;
}
public double getApr() {
return apr;
}
public double calculateInterest(){
return apr * (super.getBalance());
}
@Override
public String toString() {
return super.toString() + "\nAnnual rate of Interest: " + apr*100 +
"%\nAnnual interest: " + this.calculateInterest();
}
}
CreditCardAccount.java
public class CreditCardAccount extends Account{
private double apr;
private double creditLimit;
public CreditCardAccount(){
super(); // calls the no-arg constructor of Account class
this.apr = 0.0;
this.creditLimit = 0.0;
}
public CreditCardAccount(long number, double balance, double
apr, double creditLimit) {
super(number, balance);
this.apr = apr/100;
this.creditLimit = creditLimit;
}
public double getApr() {
return apr;
}
public void setApr(double apr) {
this.apr = apr;
}
public double getCreditLimit() {
return creditLimit;
}
public void setCreditLimit(double creditLimit) {
this.creditLimit = creditLimit;
}
@Override
public void withdraw(double amt)
{
if(amt < (super.getBalance() + creditLimit))
{
// if the sum of credit limit and balance is less than the amount
to withdraw, you can withdraw
super.setBalance(super.getBalance() - amt);
}
}
public double calculatePayment(){
double amount;
if(super.getBalance() > 0)
amount = 0;
else
amount = 20 + ((this.apr / 12) * (-super.getBalance()));
return amount;
}
@Override
public String toString(){
return super.toString() + "\nAnnual rate of interest: " + this.apr
* 100 + "%\nCredit Limit: " + this.creditLimit + "\nMonthly
payment: " + this.calculatePayment();
}
}
TestAccounts.java
public class TestAccounts {
public static void main(String... args){
Account[] accounts = new Account[5];
// since Account is the super class of SavingsAccount and
CreditCardAccount
// it can hold the instances of SavingsAccount and
CreditCardAccount
accounts[0] = new Account(1066, 7500);
accounts[1] = new SavingsAccount(30507, 4500, 1.5);
accounts[2] = new CreditCardAccount(51782737, 7000,8,1000);
accounts[3] = new CreditCardAccount(629553328, 1500, 7.5,
5000);
accounts[4] = new CreditCardAccount(497720104, -5000, 7,
10000);
// this is a foreach loop, it will take out objects from accounts
array one by one
// store them in variable "account" and performs operations on
them
for(Account account : accounts)
{
account.deposit(2134);
account.withdraw(4782);
System.out.println(account);
System.out.println();
}
}
}
The Account class Create a class named Account, which has the following private properties: number: long...
9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...
Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...
(The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...
IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...
JAVA Create a class called SavingsAccount. The class should have a static variable named, annualInterestRate, to store the annual interest rate for all account holders. Each object of the class should contain a private instance variable named, savingsBalance, indicating the amount the saver currently has on deposit. Write methods to perform the following: calculateMonthlyInterest – calculates the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12. This interest should be added to the balance. depositAmount – allows the...
In C++: Define a class named Account that stores a balance (monetary amount). The class should have a private double variable balance. Add one accessor getBalance function that returns the balance and one deposit function that increases the balance by a given double amount. Then subclass Account with a SavingsAccount class. This class should have a private double variable interest. Add an addInterest function that increases the balance (from the superclass Account) according to the interest. Demonstrate the use in...
PYTHON PROGRAMMING LANGUAGE
Design a class named Savings Account that contains: A private int data field named id for the savings account. A private float data field named balance for the savings account. A private float data field named annuallnterestRate that stores the current interest rate. A_init_ that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). . The accessor and mutator methods for id, balance, and annuallnterestRate. A method...
C++ Create a class named SavingsAccount that contains the following: Three (3) private class variables: a String called ‘name’, a double called “balance” and another double called “interestRate” and 4 function prototypes. A constructor that receives 3 parameters: a string, and 2 doubles; the constructor will use these parameters to initialize the name, the balance, and the interestRate respectively. setBalance: it receives a double parameter called theBalance and assigns it to the balance. getBalance: it returns the balance. calculateInterestAmount: it...
TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...
Now create another class named SavingsAccount. This should be a subclass of BankAccount. A SavingsAccount should have an interest rate that is specified in its constructor. Furthermore, there should be a method, addInterest, that deposits interest into account, based on the account balance and interest rate. Create another subclass of BankAccount named CheckingAccount. A CheckingAccount should keep track of the number of transactions made (deposits and withdrawals). Name this field transactionCount. Also, the set fee for transactions is three dollars,...