我是 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;
}
}