有从其他类文件中获取对象的问题...
这个功能让我们接收标题(来自电影类)和名字(来自剧院类)。 2来自用户的输入询问标题和名称是什么,从那里我们需要拍摄一个电影对象和影院对象来检查标题是否可以在电影类中找到。同样在剧院课堂上命名。
public MovieScreening(Movie movieObject,Theatre theatreObject){
this.movieObject = movieObject;
this.theatreObject = theatreObject;
}
public Movie getMovieObject() {
return movieObject;
}
public Theatre getTheatreObject() {
return theatreObject;
}
答案 0 :(得分:0)
你的代码错误且不完整,所以我几乎不知道你在这里想要什么。
但也许,下面这段代码可以帮助你。请说明更好的问题。
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]]