2014-01-26 4 views
-2

Имея вопрос получения объекта из другого файла класса ...Получить объект из другого файла класса

Эта функция возьмём в названии (от класса фильма) и название (от театрального класса). 2 вход от пользователя, спрашивающего, что такое название и имя, оттуда нам нужно взять объект фильма и объект театра, чтобы проверить, можно ли найти название в классе фильма. то же название в классе театра.

public MovieScreening(Movie movieObject,Theatre theatreObject){ 
    this.movieObject = movieObject; 
    this.theatreObject = theatreObject; 
} 

public Movie getMovieObject() { 
    return movieObject; 
} 

public Theatre getTheatreObject() { 
    return theatreObject; 
} 
+1

Вы не получаете объекты из файлов классов. – EJP

+0

Да, я знаю .. но я не знаю, как получить «getName» и «getTitle» – user3230289

+0

Что вы подразумеваете под «как получить getName и getTitle» –

ответ

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]] 
Смежные вопросы