0

At this point I'm just trying to get something to come out of what little I have and nothing is working.

So I start out with a driver class:

    class TheDriverClass
    {
      public static void main(String[] args)
      {
        Phone p = new Phone(5);
        System.out.println(p); 
  // Here it's supposed to return the values of an array with size 5, 
  //so it should print out 00000
       }
     }

Next I have the class Phone:

   class Phone
   {
       private Phone[] arr; //I'm supposed to keep the array private
       public Phone(int theLength){
          arr = new Phone[theLength];
          return Arrays.toString(arr);
       }
   }

Now it looks a little ridiculous because I've become desperate to get at least SOMETHING out and I've exhausted any and all ideas.

What is supposed to happen is that the driver class gives Phone a number which will be used as theLength of the array (arr), and the array is initialized with that length (all integers of the array defaulted to 0) and returns as many 0's as the array is long (or if I were to assign different values at different locations of the array, it will go through and print every value in the order it is placed in the array).

captastic
  • 67
  • 9

1 Answers1

1

Your constructor will not be returning anything

public Phone(int theLength){
      arr = new Phone[theLength];
}

But you will need a getter

public Phone[] getPhones () {
    return arr;
}

Usually I would have separate classes that hold the Phone array and the Phone Object itself only deals with the functionality of the actual phone.

Scary Wombat
  • 44,617
  • 6
  • 35
  • 64