Results 1 to 8 of 8
Thread: Designing an Account Class
- 11-04-2011, 04:13 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 38
- Rep Power
- 0
Designing an Account Class
Here is my attempt: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 account.
- A constructor that creates an account with the specific id and initial balance.
- The accessor and mutator methods for id, balance, and annualInterestRate.
- The accessor method for dateCreated
- A method named getMonthlyInterestRate() that returns the monthly interest rate.
- A method named withdraw that withdraws a specified amount from the account
- A method named deposit that deposits a specified amount to the account.
Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500, use the deposit method to deposit $3,000 and print the balanace, the monthly interest, and the date when this account was created.
My program won't compile and I get several error messages. I don't know how to correct all the errors. Even if I were to correct all these errors I know my program still wouldn't function correctly. How can I get this program to work?Java Code:import java.util.Date; public class AccountProblem { public static void main(String[] args) { //create an instance object of class Stock Account myAccount = new Account(1122, 20000.00, 0.045); myAccount.withdraw(2500.00); myAccount.deposit(3000.00); //display balance, monthly interest and date of account System.out.println("Balance: " + myAccount.balance); System.out.println("Monthly Interest: " + myAccount.getMonthlyInterestRate()); System.out.println("Account created on: " + myAccount.dateCreated); } } class Account { //define var1, var2 int id; double balance; double annualInterestRate; Date dateCreated; //no arg constructer Account() { id = 0; balance = 0.0; annualInterestRate = 0.0; } //constructor with specific id and initial balance Account(int newId, double newBalance) { id = newId; balance = newBalance; } //accessor/mutator methods for id, balance, and annualInterestRate public int getId() { return id; } public double getBalance() { return balance; } public double getAnnualInterestRate() { return annualInterestRate; } public void setId() { id = newId; } public void setBalance() { balance = newBalance; } public void setAnnualInterestRate() { annualInterestRate = newAnnualInterestRate; } //accessor method for dateCreated public void setDateCreated() { dateCreated = newDateCreated; } //define method getMonthlyInterestRate double getMonthlyInterestRate() { return annualInterestRate/12; } //define method withdraw double withdraw(double amount) { return balance -= amount; } //define method deposit double deposit(double amount) { return balance += amount; } }
-
Re: Designing an Account Class
- What errors?: if you have any, you should post the exact error message, else how will we know what's wrong.
- Don't try to add good code to bad code. If you're not using an IDE, always compile early and often, and always fix any compilation errors before trying to add any more code.
- Remember that setter methods require a parameter. How can you set a variable to anything if you don't tell it what to set it to?
- 11-04-2011, 06:15 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 38
- Rep Power
- 0
Re: Designing an Account Class
These are the errors I get:
setter method??? Do you mean mutator method? and where exactly do I put the parameter.AccountProblem.java:10: cannot find symbol
symbol : constructor Account(int,double,double)
location: class Account
Account myAccount = new Account(1122, 20000.00, 0.045);
^
AccountProblem.java:48: cannot find symbol
symbol : variable newId
location: class Account
id = newId;
^
AccountProblem.java:51: cannot find symbol
symbol : variable newBalance
location: class Account
balance = newBalance;
^
AccountProblem.java:54: cannot find symbol
symbol : variable newAnnualInterestRate
location: class Account
annualInterestRate = newAnnualInterestRate;
^
AccountProblem.java:58: cannot find symbol
symbol : variable newDateCreated
location: class Account
dateCreated = newDateCreated;
^
5 errors
-
Re: Designing an Account Class
- 11-05-2011, 04:43 PM #5
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Designing an Account Class
Is this your post as well: Designing an Account Class ? If so, please read the links provided in that thread regarding crossposting
Last edited by doWhile; 11-05-2011 at 04:45 PM.
- 11-05-2011, 09:50 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 38
- Rep Power
- 0
Re: Designing an Account Class
@Fubarable Uh okay.
@doWhile Sorry I didn't know cross posting wasn't allowed on this site. It won't happen again. You can close this thread now.
-
Re: Designing an Account Class
It's not "not allowed". It's just that if you do it, please notify us and them. Nobody likes to waste time answering a question that's already been answered or repeating a point that's already been made, least of all volunteers. We appreciate your respecting this, that's all.
- 11-06-2011, 07:48 PM #8
Member
- Join Date
- Oct 2010
- Posts
- 38
- Rep Power
- 0
Similar Threads
-
designing a save system
By aianta in forum New To JavaReplies: 4Last Post: 04-12-2011, 12:25 AM -
The Proper Class Design For Designing a Custom Language Type System
By abdulsami in forum Advanced JavaReplies: 2Last Post: 02-17-2011, 05:15 AM -
Help designing a program
By np2392 in forum New To JavaReplies: 2Last Post: 09-24-2010, 02:31 AM -
Create a java class for a bank account!!?
By singh345 in forum New To JavaReplies: 1Last Post: 03-17-2010, 04:26 PM -
Need help for coding and designing
By g.ganiraju in forum New To JavaReplies: 11Last Post: 11-01-2008, 04:49 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks