here is an exercise I can't figure out. Anybody know how?
Exercise 5.3
Write a class named Account to model accounts. The properties and methods are shown below. Interest is compounded monthly
Account private int id private double balance private double annualInterestRate
public Account( ) public Account( int id, double balance, double annualInterestRate)
public int getId( ) public double getBalance( ) public double getAnnualInterestRate( ) public void setId(int id) public void setBalance(double balance) public void setAnnualInterestRate(double annualInterestRate) public double getMonthlyInterest ( ) public void withdraw(double amount) public void deposit(double amount)
The Account class contains properties id, balance, annual interest rate, accessor methods, and the methods for computing interest, withdrawing money, and depositing money.
Write a client program to test the Account class. Int the client program, create an Account object with account id of 1122, balance of 20000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2500, use the deposit method to deposit $3000, and print the balance and monthly interest.
I don't see how this exercise could be any simpler. It spells out exactly what you should do and how. It isn't asking you to design a natural language parser for verbal input of account information, or anything of that nature...
YOur account class is going to do a few things, with the withdrawl() method, your just going to have it pass in a parameter to get the amount of the withdrawl. And all it is gonna do is take that parameter and subtract it from your account balance. So
public double accountB=0; public void withDrawl(double amountOfMoney) { accountB-=amountOfMoney; }
And then you will do the same for your deposit only you will use the += command.
Your interest method is going to do about the same but it will have no parameter and it will just take the accountB=accountB*.05; or whatever the interest rate it. Hope this helps man, later.