I had encounter a problem in my task.
How come the output always return false?
public class Entity {
private String itemCode;
private String title;
private String description;
private int language;
private int time;
private String productCompany;
private int status;
public Entity(){
itemCode="E250";
title="The Lookout";
description="by Scott Frank";
language=1;
time=1900;
productCompany="BB Sdn. Bhd.";
status=1;
}
public Entity(String code, String title, String description, int language, int time, String company, int status) {
itemCode=code;
this.title=title;
this.description=description;
this.language=language;
this.time=time;
productCompany=company;
this.status=status;
}
public void setItemCode(String code){
itemCode=code;
}
public String getItemCode(){
return itemCode;
}
public void setTitle(String title){
this.title=title;
}
public String getTitle(){
return title;
}
public void setDescription(String description){
this.description=description;
}
public String getDescription(){
return description;
}
public void setLanguage(int language){
this.language=language;
}
public int getLanguage(){
return language;
}
public void setTime(int time){
this.time=time;
}
public int getTime(){
return time;
}
public void setProductCompany(String company){
productCompany=company;
}
public String getProductCompany(){
return productCompany;
}
public void setStatus(int status){
this.status=status;
}
public int getStatus(){
return status;
}
public static void CheckObject(Entity[] object){
boolean test=false;
for(int i=0;i<object.length;i++){
if (object[i]!=null&&object[i].equals(object[i+1]))
test=true;
System.out.println(test);
}
}
}
public class TestEntity {
public static void main(String[] args) {
Entity film[]=new Entity[6];
film[0]=new Entity();
film[1]=new Entity("C305","Fu Lu Shou","jack",2,1500,"CC Sdn. Bhd.",2);
film[2]=new Entity("C305","Fu Lu Shou","jack",2,1500,"CC Sdn. Bhd.",2);
boolean check=false;
Entity.CheckObject(film);
System.out.print(check);
for (int i=0; i<film.length; i++){
if (film[i]!=null){
System.out.println(film[i].getItemCode()+ film[i].getTitle() + film[i].getDescription()+ film[i].getLanguage()
+ film[i].getTime() + film[i].getProductCompany() + film[i].getStatus() );
}
}
}
}