#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Simple constructor question


    Create two constructors - one which takes two double parameters (the initial values of x,y). The
    * second constructor will take another Geocache and initialize itself based on that geocache.
    *
    * For both constructors set the Geocache's id to the current value of count (thus the first geocache will have the value zero)
    * when the Geocache is created, then increment the count value.


    Question 1: So I created first constructor, and second one requires me to take another constructor and initialize itself based on that geocache.. how do i do that?

    Question 2: How do I do the count part too?
    ____________________________________________
    class Geocache {

    private int x, y;
    private double id;

    public Geocache(double a, double b){

    a= x;
    b= y;
    id=0;

    }
    public Geocache(
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,644
    Rep Power
    1945
    As specified it will take a Geocache as argument instead of two double's.

    Then you will have to read the values from the passed object. (you do know how to get the value from your object?)

    One note about the id, it sounds like it is a counter shared across all instances of Geocache. To do this, you have to make it a static variable.

IMN logo majestic logo threadwatch logo seochat tools logo