I need to print the following array and am not sure how to do so. It uses an object which is already created named TimeAT....


mport java.util.Scanner;
import java.util.Random;

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

 * @author Cory
public class hw6Main 
    public static void main(String [] args)

    final int arrayNumber;

    // Create Scanner object
    Scanner keyboard = new Scanner(System.in);

    System.out.println("Enter the size of the array: ");

    arrayNumber = keyboard.nextInt();

    if (arrayNumber < 5 || arrayNumber > 100)
        System.out.println("Invalid input amount");

    TimeAT[] time = new TimeAT[arrayNumber];



    private static void getItems(TimeAT[] time) 

     int hours;
     int minutes;

     for (int index = 0; index < time.length; index++)
     Random randomNumbers = new Random();

     hours = randomNumbers.nextInt();
     minutes = randomNumbers.nextInt();


     time[index] = new TimeAT(hours, minutes);




Edited 3 Years Ago by happygeek: fixed formatting

What exactly is it you want to print? At the moment you are printing only empty lines. If you actually want to print something, don't you think you should be inserting something into those println statements?

You need to write a toString() method for your TimerAT object that converts an instance to a String representation. Then you can just loop over the array and print each one using a call to

System.out.println( time[index].toString() );
This article has been dead for over six months. Start a new discussion instead.