I have some problem with this, and can't think of anymore solution.
I want the result to show when the user trying to add a movie title & theatre name that is inside the list, it will show another user input (year,month,day,hour,min).
But if the list can't find any name/title match, it will print out "Your movie or/and theatre cannot be found."
This is the code that I have typed so far.
public void addScreening() {
System.out.println("-ADD NEW SCREENING-");
String mTitle = Helper.readString("Enter movie title > ");
String tName = Helper.readString("Enter theatre name > ");
for (int i = 0; i < movies.size(); i++) {for (int j = 0; j < theatres.size(); j++) {
if ((movies.get(i).getTitle().contains(mTitle) && movies.get(i)
.getTitle() != null)
&& (theatres.get(j).getName().contains(tName) && theatres
.get(j).getName() != null)) {
int year = Helper.readInt("Enter year > ");
int month = Helper.readInt("Enter month > ");
int day = Helper.readInt("Enter day > ");
int hour = Helper.readInt("Enter hour > ");
int min = Helper.readInt("Enter min > ");
screenings.add(new MovieScreening(Helper.thisDate(year,
month, day, hour, min), movies.get(i), theatres
.get(j), 0));
System.out.println("Added successfully");
break;
} else if ((!movies.get(i).getTitle().contains(mTitle))
|| (!theatres.get(j).getName().contains(tName))) {
System.out
.println("Your movie or/and theatre cannot be found.");
break;
}
}
}
}
If its comparing the first index inside the list [0], its possible, but I can't seems to compare it with the other index.
Lets take it that Movie & Theatre name have "a" & "b".
Movie title: "a", "b"
Theatre name: "a", "b"
output
-Add New Movie Screening-
Enter movie title > a
Enter theatre name > a
// User input
Added Successfully
Your movie or/and theatre cannot be found.
Your movie or/and theatre cannot be found.
-----------
-Add New Movie Screening-
Enter movie title > a
Enter theatre name > b
Your movie or/and theatre cannot be found.
Your movie or/and theatre cannot be found.
Your movie or/and theatre cannot be found.
-----------
-Add New Movie Screening-
Enter movie title > b
Enter theatre name > a
Your movie or/and theatre cannot be found.
// user input
Added successfully
Your movie or/and theatre cannot be found.
-----------
-ADD NEW SCREENING-
Enter movie title > b
Enter theatre name > b
Your movie or/and theatre cannot be found.
Your movie or/and theatre cannot be found.
Your movie or/and theatre cannot be found.
Normally this input should be successful as there is "a" and "b" inside the list.
Enter movie title > a
Enter theatre name > b
-----------
Enter movie title > b
Enter theatre name > b
I think the problem is that it can't go through all the list in theatre.
Need help giving tips on how to go through multiple list.
Have tried using iterator(), but the problem is also close to this.
public void addScreening() {
System.out.println("-ADD NEW SCREENING-");
String mTitle = Helper.readString("Enter movie title > ");
String tName = Helper.readString("Enter theatre name > ");
Iterator<Movie> it1 = movies.iterator();
Iterator<Theatre> it2 = theatres.iterator();
while(it1.hasNext() && it2.hasNext()){
Movie a = it1.next();
Theatre b = it2.next();
if((a.getTitle().contains(mTitle) ) && (b.getName().contains(tName) )){
int year = Helper.readInt("Enter year > ");
int month = Helper.readInt("Enter month > ");
int day = Helper.readInt("Enter day > ");
int hour = Helper.readInt("Enter hour > ");
int min = Helper.readInt("Enter min > ");
screenings.add(new MovieScreening(Helper.thisDate(year, month, day, hour, min),a,b,0));
System.out.println("Added successfully");
break;
}else{
System.out.println("Your movie or/and theatre cannot be found. 2");
}
}
}