I need help designing a class named Account that contains.  A data field named id for the account (default 0 ). A data field named balance for the account (default 0.0 ). A data field named annualInterestRate that stores the current interest rate (default 0.0 ). Assume all accounts have the same interest rate. Program can create a default account. Program can create an account with a specified id and initial balance. A method named getMonthlyInterest() returns the amount of interest an account earned that month. A method named setInterestRate() that receives and sets the interest rate for all accounts. A method named getInterestRate() that returns the interest rate for all accounts. A method named withdraw() that withdraws a specified amount from the account returns T or F. A method named deposit() that deposits a specified amount to the account returns T or F. A method named getBalance() that returns the balance amount to the account. (Hint: The method getMonthlyInterest() is to return monthly interest earned, not the interest rate. As well as a test driver that creates an Account object and test all aspects of the designed Accounts class. This Java program will create a default account and create an account with the specified id and initial balance.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help designing a class named Account that contains. 

  • A data field named id for the account (default 0 ).
  • A data field named balance for the account (default 0.0 ).
  • A data field named annualInterestRate that stores the current interest rate (default 0.0 ). Assume all accounts have the same interest rate.
  • Program can create a default account.
  • Program can create an account with a specified id and initial balance.
  • A method named getMonthlyInterest() returns the amount of interest an account earned that month.
  • A method named setInterestRate() that receives and sets the interest rate for all accounts.
  • A method named getInterestRate() that returns the interest rate for all accounts.
  • A method named withdraw() that withdraws a specified amount from the account returns T or F.
  • A method named deposit() that deposits a specified amount to the account returns T or F.
  • A method named getBalance() that returns the balance amount to the account.

(Hint: The method getMonthlyInterest() is to return monthly interest earned, not the interest rate.

As well as a test driver that creates an Account object and test all aspects of the designed Accounts class.

This Java program will create a default account and create an account with the specified id and initial balance. 

 

Expert Solution
Step 1

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
 public static void main (String[] args) throws java.lang.Exception
 {
  // your code goes here
  Account acc = new Account();
  acc.SetID(1122);
  acc.SetBalance(20000);
  acc.SetIntrestRate(4.5);
  System.out.println("After withdraw balance : "+acc.withdraw(2500));
  System.out.println("After deposit balance : "+acc.deposit(3000));
  System.out.println("Monthly intrest is : "+acc.getMonthlyIntrest());
  System.out.println("Date when account is created : "+acc.GetDateCreated().toString());
  System.out.println("Checking for insufficiant funds -> "+acc.withdraw(50000));
 }
}


class Account
{
    private int id;
    private double balance;
    private double annualIntrestRate;
    private Date dateCreated;
    
    Account()
    {
        id = 0;
        balance = 0.0;
        annualIntrestRate = 0.0;
        dateCreated = new Date();
    }
    
    Account(int id,double balance)
    {
        this.id = id;
        this.balance = balance;
        annualIntrestRate = 0.0;
        dateCreated = new Date();
    }
    
    public int GetID()
    {
        return id;
    }
    public double GetBalance()
    {
        return balance;
    }
    public double GetIntrestRate()
    {
        return annualIntrestRate;
    }
    
    public void SetID(int id)
    {
        this.id = id;
    }
    public void SetBalance(double balance)
    {
        this.balance = balance;
    }
    public void SetIntrestRate(double intrestRate)
    {
        this.annualIntrestRate = intrestRate;
    }
    
    public Date GetDateCreated()
    {
        return dateCreated;
    }
    
    public double getMonthlyIntrest()
    {
        double monthIntrestRate = annualIntrestRate/12;
        return (balance * monthIntrestRate)/100;
    }
    
    public double withdraw(double amount)
    {
        if(!(balance-amount < 0))
        {
            balance -= amount;
        }
        else
        {
            System.out.println("Can't withdraw more than balance");
        }
        return balance;
    }
    
    public double deposit(double amount)
    {
        balance += amount;
        return balance;
    }
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education