Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Rep Power

    Default Constructors & Methods

    Hi, I have to stimulate a bank account, pretty basic
    this is what I'm required to do
    stores the account number (as a long), the name associated with the account, and the balance (as a double);
    Has a constructor which initializes the three values to given parameter values;
    Has accessor methods to get the value of the balance and the account number;
    I've got the first part done, but what does it mean to have a constructor that initializes 3 values? and the accessor methods?
    any help would do!

    This is what I have so far..

    Java Code:
    public class Account {
    	private double balance, name;
    	private long acctNumber;
    		public Account (double name, long acctNumber, 
                    double balance)
    			{ = name;
    			this.acctNumber = acctNumber;
    			this.balance = balance;
    		public Account ()
    			balance = 2000.0;

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    what does it mean to have a constructor that initializes 3 values?

    It means to write a constructor like the first one you have which initialises etc. (The other constructor doesn't make a lot of sense and should probably be removed.)

    and the accessor methods?

    "Accessor" methods are those that get or set (ie access) certain properties of an object. SO, for instance, an accessor method to get the balance might look like this:

    Java Code:
        /** Returns the balance of this account.*/
    public double getBalance() {
        // ...

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Formulas in methods or constructors?
    By kyameron in forum New To Java
    Replies: 11
    Last Post: 11-20-2010, 12:22 PM
  3. Constructors
    By in forum New To Java
    Replies: 5
    Last Post: 10-20-2010, 12:10 AM
  4. Calling subclassed methods from constructors
    By arefeh in forum New To Java
    Replies: 7
    Last Post: 01-22-2010, 12:22 AM
  5. Constructors
    By new2java2009 in forum New To Java
    Replies: 5
    Last Post: 08-18-2009, 06:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts