The Artima Developer Community
Sponsored Link

Java Answers Forum
designing classes

3 replies on 1 page. Most recent reply: Aug 12, 2002 8:21 PM by jake

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Jenga

Posts: 3
Nickname: topazz
Registered: Jul, 2002

designing classes Posted: Aug 12, 2002 1:22 PM
Reply to this message Reply
Advertisement
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.


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: designing classes Posted: Aug 12, 2002 1:33 PM
Reply to this message Reply
Have you considered another major?

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...

jake

Posts: 83
Nickname: onorok
Registered: May, 2002

Re: designing classes Posted: Aug 12, 2002 8:19 PM
Reply to this message Reply
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.

jake

Posts: 83
Nickname: onorok
Registered: May, 2002

Re: designing classes Posted: Aug 12, 2002 8:21 PM
Reply to this message Reply
that method that I wrote in the above has a minus equals command if you can't see it.

Flat View: This topic has 3 replies on 1 page
Topic: help with adding image to applet Previous Topic   Next Topic Topic: Java curser on a text field

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use