“找不到符号 - 变量”,但......它存在

时间:2013-10-09 08:18:58

标签: java variables bluej

我是Java的新手。我的作业是写一个CinemaBookingSystem程序。这是我的主要课程:

public class CinemaBookingSystem
{
    private String CinemaName;
    private Screening screening1;  
    private Screening screening2;   
    private Screening screening3;   
    private Screening screening4; 
    private Screening screening5;   
    private Screening screening6;   
    private Screening screening7;   
    private Screening screening8;   

    /**
     *
     */
    public CinemaBookingSystem()
    {
        Movie movie1 = new Movie("Nemo", 12);
        Movie movie2 = new Movie("Toy's Story", 11);
        Movie movie3 = new Movie("Mulan", 11);
        Movie movie4 = new Movie("Spirited Away", 10);
        Movie movie5 = new Movie("Pocahontas", 11);
        Movie movie6 = new Movie("Garfield", 10);
        Movie movie7 = new Movie("Lord of the Rings", 9);
        Movie movie8 = new Movie("Cloud Atlas", 8);

        Date date1 = new Date("Monday", 16.30);
        Date date2 = new Date("Tuesday", 12.30);
        Date date3 = new Date("Monday", 15.30);
        Date date4 = new Date("Tuesday", 18.00);

        Hall hall1 = new Hall(20, 40);
        Hall hall2 = new Hall(30, 50);
        Hall hall3 = new Hall(40, 50);
        Hall hall4 = new Hall(50, 60);

        Screening screening1 = new Screening(movie1, date1, hall1);
        this.screening1 = screening1;
        Screening screening2 = new Screening(movie2, date2, hall1);
        this.screening2 = screening2;
        Screening screening3 = new Screening(movie3, date3, hall2);
        this.screening3 = screening3;
        Screening screening4 = new Screening(movie4, date4, hall2);
        this.screening4 = screening4;
        Screening screening5 = new Screening(movie5, date1, hall3);
        this.screening5 = screening5;
        Screening screening6 = new Screening(movie6, date2, hall3);
        this.screening6 = screening6;
        Screening screening7 = new Screening(movie7, date3, hall4);
        this.screening7 = screening7;
        Screening screening8 = new Screening(movie8, date4, hall4);
        this.screening8 = screening8;

    }


    public void reserve(Screening screening, int row, int seat)
    {
        if(screening.returnSeatsMap()[row][seat].getSeatsState()==true)
            screening.returnSeatsMap()[row][seat].reserveSeat();
        else
            System.out.print("This seat isn't available.");
    }

但是保留方法不起作用......当我调用它时,它会显示:

http://i.stack.imgur.com/J6uK6.png

但是我创建了screening1,它在字段和构造函数中......显然它不能以这种方式工作而且我可以接受它,但是从昨天开始没有其他解决方案出现在我脑海中......任何提示?

顺便说一句,抱歉所有的语法错误,我不是母语为英语的人。谢谢你的帮助!

编辑:好的我没想到问题是其他课程。 这是课程筛选:

public class Screening
{
    private Movie movie;
    private Date date;
    private Seat[][] seatsMap;
    private Hall hall;

    /**
     * 
     */
    public Screening(Movie movie, Date date, Hall hall)
    {
        this.movie = movie;
        this.date = date;
        seatsMap = new Seat[hall.getRows()][hall.getSeats()];
    }

    public Seat[][] returnSeatsMap()
    {
        return seatsMap;
    }


}

在这里霍尔:

 public class Hall
{
    private ArrayList<Screening> screenings;
    private int rows;
    private int seats;

    /**
     * 
     */
    public Hall(int rows, int seats)
    {
        this.rows = rows;
        this.seats = seats;
    }

    public int getRows()
    {
        return rows;
    }

    public int getSeats()
    {
        return seats;
    }

}

1 个答案:

答案 0 :(得分:0)

应该在调用screening1方法的位置定义符号(此处为变量reserve())。属性private Screening screeningX;应该位于调用reserve()的类中(我想,在这里没有发布的类中,因为我看不到任何reserve调用。)< / p>

注意将来,如果有几个具有相似行为的变量,请使用数组(Screening[]ArrayList<Screening>。您将能够大大简化代码。 祝你好运=)