4 Replies - 2526 Views - Last Post: 06 December 2011 - 09:05 PM Rate Topic: -----

#1 tmotley12  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 07-October 11

Account Class- error

Posted 06 December 2011 - 12:42 PM

Q: The Account class) 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 anualInterestRate 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 a specified id and initial balance.
*The accessor and mutator method for id, balance, and annualInterestRate
*The accessor method for dateCreated
* A method named getMonthlyInterestRate() that returns tyhe monthly interest rate.
*A method named withdraw that withdraws a specified amount from the account
*A method named deposit that deposits a specified amount from the account.
Draw the UML diagram for the class. Implement the class. 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 balance, the monthly interest, and the date when this account was created.



This is what a classmate and I were able to produce this morning, but I am still stuck on one error that is driving me crazy:
public Account(int id, double balance, doubleannualInterestRate)
<--- "Cannot find symbol, Identifier expected"

package account;

/**
 *
 * @author TM2011
 */

import java.util.*;


public class Account{


    private int id=0;
    private double balance = 0;
    private double annualInterestRate = 0;
    private Date dateCreated;


    public Account()
    {
    
        this.id =0;
        this.balance =0;
        this.annualInterestRate =0;
        this. dateCreated = new Date();

    }

    public Account(int id, double balance, doubleannualInterestRate)
    {
    
    this.id =id;
    this.balance =balance;
    this.annualInterestRate =annualInterestRate;
    this. dateCreated = new Date();
    }


    public void setID(int id) {
    this.id=id;
    }

    public int getID() {
    return this.id;
    }


    public void setBalance(double balance) {
    this.balance = balance;
    }


    public double getbalance(){
    return this.balance;
    }


    public void setAnnualInterestrate(double annualInterestRate) {
    this.annualInterestRate =annualInterestRate;
    }


    public double getAnnualInterestrate() {
    return this.annualInterestRate;
    }

    public Date getDateCreated() {
    return this.dateCreated;
    }

    public double getMonthlyInterestRate() {
    return (this.annualInterestRate)/12;
    }

    public void withdraw(double amount) {
    if( this.balance <amount)
    {
       System.out.println("Insufficent balance in the account");
    }
    else
    {
        this.balance -=amount;
        System.out.println("Afterwithdrawing   "+ amount +"   balance in "
                + "accountis:   " +this.balance);
    }
}

public void deposit(double amount)
{
    this.balance += amount;
    System.out.println(" Afterdepositing   " + amount  + "   balance inaccount"
            + " is:"  + this.balance);
}


public static void main(String args[]){

Account ac= new Account( 1122, 20000, 4.5);
ac.withdraw(2500);
ac.deposit(3000);

System.out.println("balance in account " + ac.getID() +"is: " +ac.getbalance());
System.out.println("Monthly Interest  is: " + (ac.getMonthlyInterestRate()  
        *  ac.getbalance()) /100);
System.out.println("Account is created on:  " +ac.getDateCreated());

    }

}


        


Thanks for taking a look!

Is This A Good Question/Topic? 0
  • +

Replies To: Account Class- error

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10183
  • View blog
  • Posts: 37,596
  • Joined: 27-December 08

Re: Account Class- error

Posted 06 December 2011 - 12:46 PM

Look here doubleannualInterestRate). You need a space between the type and name of this parameter.
Was This Post Helpful? 0
  • +
  • -

#3 Bocard  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 222
  • Joined: 24-September 08

Re: Account Class- error

Posted 06 December 2011 - 12:48 PM

in the constructor of the account you don't have a space between double and annualInterestRate.
Was This Post Helpful? 0
  • +
  • -

#4 optomusprilliam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 06-December 11

Re: Account Class- error

Posted 06 December 2011 - 08:13 PM

inside your Account parameters, the double needs a space after it
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Account Class- error

Posted 06 December 2011 - 09:05 PM

And nobody is shortsighted here, to post your text using regular font
Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1