I am currently trying to write a program that will allow me to use insertion sorting to find the title and to find the year in which the movie was released. Currently whenever I compile and run the program, I end up with a random String that looks like this "[LMovie2;@15f45c9" however, it is different every single time. If someone could help me get an idea of where I am going wrong,(possibly in my array) that would be awesome. I would also like feedback on how to ask questions since this is my first post. Thank you for your time and consideration.
public class Movie2
{
private String title;
private int year;
private String studio;
public Movie2(String t, int y, String s)
{
title = t;
studio = s;
year = y;
}
public String toString()
{
String movies;
movies = title + " \t" + year + "\t" + studio;
return movies;
}
public String getTitle()
{
return title;
}
public void setTitle(String t)
{
title = t;
}
public String getStudio()
{
return studio;
}
public void setStudio(String s)
{
studio = s;
}
public int getYear()
{
return year;
}
public void setYear(int y)
{
year = y;
}
}
public class testMovies2
{
public static void main(String[] args)
{
Movie2[] movies = new Movie2[10];
movies[0] = new Movie2("The Muppets Take Manhattan", 2001, "Columbia Tristar");
movies[1] = new Movie2("Mulan Special Edition", 2004, "Disney");
movies[2] = new Movie2("Shrek 2", 2004, "Dreamworks");
movies[3] = new Movie2("The Incredibles", 2004, "Pixar");
movies[4] = new Movie2("Nanny McPhee", 2006, "Universal");
movies[5] = new Movie2("The Curse of the Were-Rabbit", 2006, "Aardman");
movies[6] = new Movie2("Ice Age", 2002, "20th Century Fox");
movies[7] = new Movie2("Lilo & Stitch", 2002, "Disney");
movies[8] = new Movie2("Robots", 2005, "20th Century Fox");
movies[9] = new Movie2("Monsters Inc.", 2001, "Pixar");
System.out.println(movies);
}
public static void insertionSort(Movie2[] a)
{
int[] source = { 12, 14, 15, 11, 13 };
int[] dest = new int[ source.length ];
for ( int i = 0 ; i < source.length ; i++ )
{
int next = source[ i ];
int insertindex = 0;
int k = i;
while ( k > 0 && insertindex == 0 )
{
if ( next > dest[ k - 1 ] )
{
insertindex = k;
}
else
{
dest[ k ] = dest[ k - 1 ];
}
k--;
}
dest[ insertindex ] = next;
}
}
}