film class
import java.util.Scanner;
// Creating Class Members
public class film {
private String itemCode;
private String title;
private String description;
private String language;
private String runningTime;
private String productionCompany;
private String status; //eg, pending, premiering, running, written-off
// No-argument Constructor: Without Parameters
public film() {
itemCode = "";
title = "";
description = "";
language = "";
runningTime = "";
productionCompany = "";
status = "";
}
// With Argument Constructor: With Parameters
public film(String itemCode, String title, String description, String language, String runningTime, String productionCompany, String status){
this.itemCode = itemCode;
this.title = title;
this.description = description;
this.language = language;
this.runningTime = runningTime;
this.productionCompany = productionCompany;
this.status = status;
}
//Copy Constructor
public film(film films){
itemCode = films.itemCode;
title = films.title;
description = films.description;
language = films.language;
runningTime = films.runningTime;
productionCompany = films.productionCompany;
status = films.status;
}
//Setter & Getter Method, From: itemCode - status
public void setItemCode(String itemCode){
this.itemCode = itemCode;
}
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(String language){
this.language = language;
}
public String getLanguage(){
return language;
}
public void setRunningTime(String runningTime){
this.runningTime = runningTime;
}
public String getRunningTime(){
return runningTime;
}
public void setProductionCompany(String productionCompany){
this.productionCompany = productionCompany;
}
public String getProductionCompany(){
return productionCompany;
}
public void setStatus(String status){
this.status = status;
}
public String getStatus(){
return status;
}
//Method equals that return true if two objects contain the same information
public boolean equals(film filmsCompare){
if(itemCode.equals(filmsCompare.itemCode) && title.equals(filmsCompare.title) && description.equals(filmsCompare.description) && language.equals(filmsCompare.language) &&
runningTime.equals(filmsCompare.runningTime) && productionCompany.equals(filmsCompare.productionCompany) && status.equals(filmsCompare.status))
return true;
else
return false;
}
}
collection class
import java.util.Scanner;
public class collection {
film[] films = new film[100];
static int numberFilm = 0;
film[] arrFilms = new film[numberFilm];
//User Input Film Method
public void inputFilm(){
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.println("Add New Films");
System.out.println("=============");
for(char option = 'Y'; option == 'Y';){
System.out.print("Item Code: ");
String code = scan.next();
System.out.print("Title: ");
String title = scan.next();
System.out.print("Description: ");
String description = scan.next();
System.out.print("Language: ");
String language = scan.next();
System.out.print("Running Time(00:00): ");
String time = scan.next();
System.out.print("Production Company: ");
String production = scan.next();
System.out.print("Status: ");
String status = scan.next();
System.out.print("Add More?(Y/N) ");
option = scan.next().toUpperCase().charAt(0);
System.out.println();
addFilm(code, title, description, language, time, production, status);
++numberFilm;
}
}
public void addFilm(String code, String title, String description, String language, String time, String production, String status){
films[numberFilm] = new film(code, title, description, language, time, production, status);
}
//Search Film Method
public void searchFilm(){
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.println("Search Films");
System.out.println("============");
System.out.print("Please Key-in Item Code: ");
String code = scan.next();
for(int i = 0; i < arrFilms.length; i++)
if(code == arrFilms[i].getItemCode()){
System.out.println("Item Code: " + arrFilms[i].getItemCode());
System.out.println("Title: " + arrFilms[i].getTitle());
System.out.println("Description: " + arrFilms[i].getDescription());
System.out.println("Language: " + arrFilms[i].getLanguage());
System.out.println("Running Time: " + arrFilms[i].getRunningTime());
System.out.println("Production Company: " + arrFilms[i].getProductionCompany());
System.out.println("Status: " + arrFilms[i].getStatus());
System.out.println();
}
}
}
client program class
import java.util.Scanner;
public class ClientProgram {
static collection callCollection = new collection();
static int countFilm = callCollection.numberFilm;
static collection[] collectionFilms = new collection[countFilm];
static film[] filmFilms = new film[countFilm];
public static void main(String[] args){
Scanner scanMenu = new Scanner(System.in);
boolean condition = false;
do{
System.out.println();
System.out.println("Ortsa Sdn. Bhd.");
System.out.println("---------------");
System.out.println("(1) Add New Film");
System.out.println("(2) Search Film");
System.out.println("(3) Amend Film");
System.out.println("(4) Update Film Status");
System.out.println("(5) Listing Films' Details");
System.out.println("(6) Exit The Program");
System.out.println();
System.out.print("What's Your Choice: ");
int scanChoice = scanMenu.nextInt();
if(scanChoice == 1)
callCollection.inputFilm();
else if(scanChoice == 2)
callCollection.searchFilm();
else if(scanChoice == 3)
amendFilm(filmFilms);
else if(scanChoice == 4)
updateStatus(filmFilms);
else if(scanChoice == 5)
listingFilm(filmFilms);
else if(scanChoice == 6)
System.exit(0);
condition = false;
char pause = '\u0000';
while(true){
System.out.print("Press Enter Keys To Continue...");
try{
pause = (char)System.in.read();
if(pause != '\u0000')
break;
}catch(java.io.IOException ioexception){
System.out.println(ioexception);
}
}
}while(condition == false);
}
//Amend Film Method
public static void amendFilm(film[] filmFilms){
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.println("Amend Films' Details");
System.out.println("====================");
System.out.print("Please Key-in Item Code: ");
String code = scan.next();
for(int i = 0; i < collectionFilms.length; i++)
if(code == filmFilms[i].getItemCode()){
System.out.print("(0) Amend Item Code");
System.out.print("(1) Amend Title");
System.out.print("(2) Amend Description");
System.out.print("(3) Amend Language");
System.out.print("(4) Amend Running Time");
System.out.print("(5) Amend Production Company");
System.out.print("Selection: ");
int selection = scan.nextInt();
if(selection == 0){
System.out.print("Enter New Item Code: ");
filmFilms[i].setItemCode(scan.next());
}
else if(selection == 1){
System.out.print("Enter New Title: ");
filmFilms[i].setTitle(scan.next());
}
else if(selection == 2){
System.out.print("Enter New Description: ");
filmFilms[i].setDescription(scan.next());
}
else if(selection == 3){
System.out.print("Enter New Language: ");
filmFilms[i].setLanguage(scan.next());
}
else if(selection == 4){
System.out.print("Enter New Running Time: ");
filmFilms[i].setRunningTime(scan.next());
}
else if(selection == 5){
System.out.print("Enter New Production Company: ");
filmFilms[i].setProductionCompany(scan.next());
}
}
}
//Update Films' Status Method
public static void updateStatus(film[] filmFilms){
Scanner scanStatus = new Scanner(System.in);
System.out.println();
System.out.println("Status Update");
System.out.println("=============");
System.out.print("Enter Item Code: ");
String code = scanStatus.next();
for(int i = 0; i < collectionFilms.length; i++)
if(code == filmFilms[i].getItemCode()){
System.out.print("Enter New Status: ");
filmFilms[i].setStatus(scanStatus.next());
}
}
//Listing All Films' Details
public static void listingFilm(film[] filmFilms){
System.out.println();
System.out.println("Listing Films");
System.out.println("=============");
int numFilm = 1;
for(int i = 0; i < collectionFilms.length; i++, numFilm++){
System.out.println("Film " + numFilm);
System.out.println("Item Code: " + filmFilms[i].getItemCode());
System.out.println("Title: " + filmFilms[i].getTitle());
System.out.println("Description: " + filmFilms[i].getDescription());
System.out.println("Language: " + filmFilms[i].getLanguage());
System.out.println("Running Time: " + filmFilms[i].getRunningTime());
System.out.println("Production Company: " + filmFilms[i].getProductionCompany());
System.out.println("Status: " + filmFilms[i].getStatus());
System.out.println();
}
}
}
what's my problem is when i choose to add film it will go to collection class and run inputFilm method, after i finish input i go to display or amend or search, it won't display anything, where's my mistake?