0

oh yeah, i should fixed that array of user input one. my mistake. :(
but if boolean is false, how can i go ask user re-enter whole thing again with same array size? :)

0

What I would do is just call --numberFilms. The duplicate film is still there, but the next added film will overwrite the duplicate.

0

your suggestion is good enough, is making me easier to understand it. :) thanks dude.

0

but i think the numberFilm - 1 is not needed, and what is the check return false?
how can i ask the user overwrite?

0
//Add Film Method
	public static void addFilm(String code, String title, String description, String language, int time, String production, String status, Film[] callFilms){
		if(numberFilm == 0){
			callFilms[numberFilm] = new Film(code, title, description, language, time, production, status);
			++numberFilm;
		}
		else{
			boolean resultCheck = checkFilm(callFilms);
			if(resultCheck == true){
				callFilms[numberFilm] = new Film(code, title, description, language, time, production, status);
				++numberFilm;
			}
			else
				System.out.println("You've Enter Duplicate Data. Please Re-Enter Again.");
		}
	}

if i put like this way, if the check return false which mean it will display "You've Entered Duplicate Data. Please Re-Enter." and then the numberFilm still remain the current one?

0

The numberFilm-1 is needed, because the last entry in the films array is the added film. The function will always return true that way, because it will find itsself.

Think yourself about the return, and what you do with it. What does the true or false from the method mean (Duplicate or not?)?

When the user enters a duplicate, he should just return to the menu, and be able to exit or reenter a film.

0
public static boolean checkFilm(Film[] callFilms){
		Film addedFilm = callFilms[numberFilm];
		boolean check = false;
		for(int i = 0; i < numberFilm; i++){
			if(callFilms[i].equals(addedFilm))
				check = true;
			else
				check = false;
		}
		return check;
	}

i think it will not return true always,
let's give an exmaple;

imagine numberFilm = 2;
boolean check = false;
looping now from i = 0, when i < numberFilm and i never will can reach 2, or else it will error.
then do the checking, if callFilm[0/1].equals(addedFilm/callFilms[2])

0

If numberfilms is 2, there was 1 film, and the second film (which is in films[1]), is the added film. You can't ask for films[2], because there is nothing in there.

film [1] is the added film, so you should only check if the film is equal to the previous films. If you check if the film is equal to itsself, it will always return true.

0

let's check it out, if numberFilm = 2 right
then the statement will be like this

Film addFilm = callFilm[2]; // Film addFilm = callFilm[numberFilm]
0

Oh! I see my error now!
I thought: First the adding, then the loop. It is the other way around.

What I dont understand: why would you do a check, if the film has not yet been added? You should do a check after the flm has been added, and if there is a duplicate, remove it.

You can also do a check before the adding, but you'll have to make the new Film(...) first, and pass that into the checking method. The new Film(...) should then be compared to all the films already in the array.

0

but as my way to do it,
i use other variables to hold them and pass into addFilm() method,
then start do the checking, if it is duplicate then remain the numberFilm(which mean not increment or decrement of numberFilm)
then if it is not duplicate then it will pass into the constructor film() and increment the numberFilm. i think this is should be work.

0

Why would you use other variables then the ones you need? It makes code messy, and it it totally unnecessary.
I think you need to try a little yourself, and see if it works.

0

take a look of my inputFilm()
it cannot be assignment by using setter, i also don't know why. so i use other variables to hold them. :)
alright thanks a lot dude. :) may i give you a kiss? XD

0

AddFilm():

//Add Film Method
	public static void addFilm(String code, String title, String description, String language, int time, String production, String status, Film[] callFilms){
		if(numberFilm == 0){
			callFilms[numberFilm] = new Film(code, title, description, language, time, production, status);
			++numberFilm;
		}
		else{
Film addFilm = new Film(code, title, description, language, time, production, status);
			if (!checkFilm(addFilm)){
callFilms[numberFilm] = addFilm;
				++numberFilm;
}
else
System.out.println("You've Entered Duplicate Data. Please Re-Enter Again.");
		}
	}

where checkFilm is the following:

public static boolean checkFilm(Film addFilm){
		boolean check = false;
		for(int i = 0; i < numberFilm; i++){
			if(callFilms[i].equals(addFilm))
				check = true; // don't make check false if there is no duplicate, only update the variable if there is a duplicate, or the data will get lost.
		}
		return check;
	}
0

yeah, i know why you said is always return true,
because it always check for whole constructor.. that's my mistake, i should only check for itemCode, so i also made some changes of it. :) now all work successfully and correctly. Thank you dude anyway. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.