ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 08 May 2017 My Price 9.00

(Subclasses of Account) In Programming Exercise 9.7

0133593517.pdf

  1. (Subclasses of Account) In Programming Exercise 9.7, the Account class was defined to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and with- draw funds. Create two subclasses for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn. Draw the UML diagram for the classes and then implement them. Write a test program that creates objects of Account, SavingsAccount, and CheckingAccount and invokes their toString() methods.
  2. This is my code from Exercise 9.7:

public class Exercise09_07 {

public static void main (String[] args) {

 

Account account = new Account(1122, 20000);

 

account.setAnnualInterestRate(4.5);

 

account.withdraw(2500);

 

account.deposit(3000);

 

System.out.println("Balance is " + account.getBalance());

 

System.out.println("Monthly interest is " + account.getMonthlyInterest());

 

System.out.println("This account was created at " + account.getDateCreated());

 

}

 

}

 

class Account {

 

  private int id;

  private double balance;

  private double annualInterestRate;

  private java.util.Date dateCreated;

 

  Account()

  {

      this.id = 0;

      this.balance = 0;

      this.annualInterestRate = 0;

      this.dateCreated = new java.util.Date();

  }

 

  public Account(int id, double balance) {

      super();

      this.id = id;

      this.balance = balance;

      this.dateCreated = new java.util.Date();

  }

 

  public int getId() {

      return id;

  }

 

  public void setId(int id) {

      this.id = id;

  }

 

  public double getBalance() {

      return balance;

  }

 

  public void setBalance(double balance) {

      this.balance = balance;

  }

 

  public double getAnnualInterestRate() {

      return annualInterestRate;

  }

 

  public void setAnnualInterestRate(double annualInterestRate) {

      this.annualInterestRate = annualInterestRate/100;

  }

 

  public java.util.Date getDateCreated() {

      return dateCreated;

  }

 

  public double getMonthlyInterestRate()

  {

      return this.annualInterestRate / 12;

  }

   

  public double getMonthlyInterest(){

  return getMonthlyInterestRate()*this.balance;

  }

 

  public void withdraw(double amount)

  {

      this.balance = this.balance - amount;

  }

 

  public void deposit(double amount)

  {

      this.balance = this.balance + amount;

  }

     

 

 

public static void main(String[] args) {

    CheckingAccount checking = new CheckingAccount(1, 35);

    SavingsAccount savings = new SavingsAccount(2, 25);

    checking.withdraw(10);

    savings.withdraw(10);

    

    System.out.println(checking.getBalance());

    System.out.println(savings.getBalance());

  }

}

  1.  

 

Answers

(11)
Status NEW Posted 08 May 2017 07:05 AM My Price 9.00

-----------

Not Rated(0)