Ваш код неправильный и неполный, так что я едва могу представить, что вы хотите здесь.
Но, возможно, этот код ниже может помочь вам как-то. Пожалуйста, укажите лучшие вопросы.
import java.util.ArrayList;
public class Screener {
private static ArrayList <MovieScreening> screenings = new ArrayList <MovieScreening>();
/**
* @param args
*/
public static void main(String[] args) {
String movie = "Titanic";
String theatre = "Cineplex";
screenings.add(new MovieScreening(new Movie("Titanic"),new Theatre("Odeon")));
screenings.add(new MovieScreening(new Movie("run lola run"),new Theatre("Cineplex")));
screenings.add(new MovieScreening(new Movie("Titanic"),new Theatre("Cineplex")));
for(MovieScreening s:screenings){
if(s.contains(movie,theatre)){
System.out.println("Added successfully:"+s);
} else {
System.out.println("Your movie or/and theatre cannot be found:"+s);
}
}
}
}
и
public class MovieScreening {
private Movie movie;
private Theatre theatre;
public MovieScreening(Movie movie, Theatre theatre) {
this.movie = movie;
this.theatre = theatre;
}
public Movie getMovie() {
return movie;
}
public void setMovie(Movie movie) {
this.movie = movie;
}
public Theatre getTheatre() {
return theatre;
}
public void setTheatre(Theatre theatre) {
this.theatre = theatre;
}
public boolean contains(String movie, String theatre) {
return this.movie.getTitle().equals(movie) && this.theatre.getName().equals(theatre);
}
@Override
public String toString() {
return "MovieScreening [movie=" + movie + ", theatre=" + theatre + "]";
}
}
и
public class Theatre {
private String name;
public Theatre(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Theatre [name=" + name + "]";
}
}
и
public class Movie {
private String title;
public Movie(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
@Override
public String toString() {
return "Movie [title=" + title + "]";
}
}
, вероятно, даст вам выход, как этот
Your movie or/and theatre cannot be found:MovieScreening [movie=Movie [title=Titanic], theatre=Theatre [name=Odeon]]
Your movie or/and theatre cannot be found:MovieScreening [movie=Movie [title=run lola run], theatre=Theatre [name=Cineplex]]
Added successfully:MovieScreening [movie=Movie [title=Titanic], theatre=Theatre [name=Cineplex]]
Вы не получаете объекты из файлов классов. – EJP
Да, я знаю .. но я не знаю, как получить «getName» и «getTitle» – user3230289
Что вы подразумеваете под «как получить getName и getTitle» –