0

The goal that I am trying to get to is having user input the name of a movie along with the release date. To do this I have set up separate classes.

Movie cameronsMovie = new Movie("Sin City", 2005);
    Movie [] movieList = new Movie [9];
    movieList[0] = cameronsMovie;

    for (int i = 0; i < movieList.length; i++) {
        System.out.print("Please enter a movie Title: ");
        String title = GetInput.readLine(); //Get movieTitle
        System.out.print("Please enter the year it was released: ");
        int releaseDate = GetInput.readInt(); //Get year
        // creating a new ojbect
        Movie userMovie = new Movie(title, releaseDate); /* calls the 
        constructor from Movie class
        */
        movieList[i] = userMovie;
    }

    System.out.println(movieList.toString());

This is the code that I am using to call the other classes and the problem that I am having is with my last line of code printing out a result of [LMovie;@2a139a55

In my classes file I have this code

public String toString() {

       String temp = new String();
       temp = "Movie title: " + getTitle() + "\nYear of Release: " +        
              getYear();
       return(temp);

       }

to return my string. Is there something wrong with the way my toString() is set up or is there another place where I am making a mistake

CamronT
  • 25
  • 1
  • 9
  • 6
    Use `Arrays.toString(movieList)` – Eran Feb 15 '16 at 06:58
  • Never call your array *a List* – TheLostMind Feb 15 '16 at 07:01
  • Your intention is to print movie name with release date, so this should be done at object level . your toString() method should be in Movie class.And you should iterate it in for loop . but here you are just calling toString method at list level which holds list of movie object. Other way for doing this would be as suggested by Eran/Imran – Dhiraj Feb 15 '16 at 07:03

1 Answers1

1

Your questions title is a bit confusing, because you don't use an ArrayList, you use an Array. With an ArrayList, it would be no problem to print it using ArrayList.toString();

But because you use an Array, you need a helper function definded in Arrays:

 Arrays.toString(movieList);
Jörn Buitink
  • 2,906
  • 2
  • 22
  • 33
  • I did add that to my code and it worked the way it needed too. I guess my confusing question stems from my confusion with what I was doing wrong. Thank you for your help though. It is much appreciated – CamronT Feb 15 '16 at 07:10