Hello,
I was trying to display an array of objects so that it will show object information. However I did not get the right result. The result looked like this:
[LItem;@55f96302
[LItem;@55f96302
[LItem;@55f96302
[LItem;@55f96302
[LItem;@55f96302
Item class:
private String title;
private String classification;
private String genre;
private int ID;
private int year;
private Calendar dateLastReturned;
private boolean available;
private RentItem latest;
public Item(int ID, int year, String title, String classification, String genre)
{
this.ID = ID;
this.year = year;
this.title = title;
this.classification = classification;
this.genre = genre;
dateLastReturned = null;
available = true;
latest = null;
}
public Item()
{
ID = 0;
year = 0;
title = "";
classification = "";
genre = "";
available = true;
dateLastReturned = null;
latest = null;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getClassification() {
return classification;
}
public void setClassification(String classification) {
this.classification = classification;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public Calendar getDateLastReturned() {
return dateLastReturned;
}
public void setDateLastReturned(Calendar dateLastReturned) {
this.dateLastReturned = dateLastReturned;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public RentItem getLatest() {
return latest;
}
public void setLatest(RentItem latest) {
this.latest = latest;
}
public void returnItem(Calendar endDate)
{
setDateLastReturned(endDate);
available = true;
}
public String toString()
{
String str = "";
str= str + "ID: "+ID + "\n"+"Year: "+year+"\n"+"Title: "+title+"\n"+"Classification: "+ classification+"\n"+"Genre: "+genre+"\n";
str = str +"Return Date: "+retDay+"/"+retMonth+"/"+retYear+"\n"+"Available: "+available+"\n";
if (getLatest() != null)
str = str + "Most Recent Rental:"+"\t\t\t\t" +getLatest().getReference();
return str;
}
DVD class(This class is the subclass of the Item class):
private int numberOfDiscs;
private int filmRunTime;
private String subtitles;
public DVD(int ID, int year, String title, String classification, String genre, int numberOfDiscs, int filmRunTime, String subtitles)
{
this.numberOfDiscs = numberOfDiscs;
this.filmRunTime = filmRunTime;
this.subtitles = subtitles;
}
public DVD()
{
numberOfDiscs = 0;
filmRunTime = 0;
subtitles = "";
}
public int getNumberOfDiscs() {
return numberOfDiscs;
}
public void setNumberOfDiscs(int numberOfDiscs) {
this.numberOfDiscs = numberOfDiscs;
}
public int getFilmRunTime() {
return filmRunTime;
}
public void setFilmRunTime(int filmRunTime) {
this.filmRunTime = filmRunTime;
}
public String getSubtitles() {
return subtitles;
}
public void setSubtitles(String subtitles) {
this.subtitles = subtitles;
}
@Override
public String toString() {
return "DVD [numberOfDiscs=" + numberOfDiscs + ", filmRunTime="
+ filmRunTime + ", subtitles=" + subtitles + ", getTitle()="
+ getTitle() + ", getClassification()=" + getClassification()
+ ", getGenre()=" + getGenre() + ", getID()=" + getID()
+ ", getYear()=" + getYear() + ", getDateLastReturned()="
+ getDateLastReturned() + ", isAvailable()=" + isAvailable()
+ ", getLatest()=" + getLatest() + ", toString()="
+ super.toString() + ", getClass()=" + getClass()
+ ", hashCode()=" + hashCode() + "]";
}
What I have tried:
I have tried the following:
static Item[] productStorage= new Item[2];
public static void initialise()
{
DVD dvd1 = new DVD(1, 2010, "Shutter Islands", "16", "Mystery, Thriller", 1, 138, "French, Polish, English");
DVD dvd2 = new DVD(2, 2006, "Prestige", "12", "Drama, Mystery", 1, 130, "English, German, French, Spanish");
productStorage[0] = dvd1;
productStorage[1] = dvd2;
for(int i = 0; i < productStorage.length; i++)
{
System.out.println(productStorage);
}
}
However it displays it like that:
[LItem;@55f96302
[LItem;@55f96302
Any help will be appreciated
Thanks!