所以基本上,我有 2 个课程(到目前为止)“座位”和“剧院”以及我的主要方法。
我要制作一个电影院预订系统,为此我需要使用数组创建一个“电影院”。但是我希望能够制作尽可能多的这些电影院,并且我可能会添加其他变量,例如(时间、电影等),我想我会制作一个包含座位数组的“剧院”类在它的构造函数中,然后有一个显示数组的方法,但是我不确定如何执行它。
这是我到目前为止所拥有的”
主类:
public class CinemaSystem {
public static void main(String[] args) {
// Creating a cinema.
Theatre cinema1 = new Theatre();
Scanner scan = new Scanner(System.in);
Scanner scan1 = new Scanner(System.in);
System.out.print("Welcome to the Theatre Booking System. (QUIT to exit)"
+ "\nWould you like to purchase tickets or list available seats?"
+ "(/Purchase/List/Help)");
String answer, answer2;
answer = scan.nextLine();
int count = 0;
if (answer.equalsIgnoreCase("purchase")) {
cinema1.DisplayTheatre(Seat
y[][]
);
} else if (answer.equalsIgnoreCase("list")) {
} else if (answer.equalsIgnoreCase("help")) {
// Code for help
} else if (answer.equalsIgnoreCase("quit")) {
System.exit(-1);
} else {
do {
System.out.print("Sorry, incorrect input please enter"
+ " a valid input (Purchase/List/Help or QUIT to exit");
answer = scan1.nextLine();
count++;
if (answer.equalsIgnoreCase("purchase")) {
// Code for purchase
} else if (answer.equalsIgnoreCase("list")) {
// Code for list
} else if (answer.equalsIgnoreCase("help")) {
// Code for help
} else if (answer.equalsIgnoreCase("quit")) {
System.exit(-1);
} else if (count == 3) {
System.out.print("Are you stupid? Purchase/List/Help or Quit are your options. ... Terminating...");
System.out.println();
System.exit(1);
}
} while (!answer.equalsIgnoreCase("purchase")
|| !answer.equalsIgnoreCase("list")
|| !answer.equalsIgnoreCase("help")
|| !answer.equalsIgnoreCase("quit"));
}
}
}
座位等级:
public class Seat {
public Seat() {
}
private String type;
private boolean status;
public String GetType() {
return type;
}
public void SetType(String x) {
type = x;
}
public boolean SetStatus() {
return status;
}
public void GetStatus(boolean x) {
status = x;
}
}
戏剧课:
public class Theatre{
public Theatre() {
Seat B = new Seat();
Seat S = new Seat();
Seat G = new Seat();
Seat y[][] = {
{B, B, B, B, B, B, B, B},
{B, B, B, B, B, B, B, B},
{B, B, B, B, B, B, B, B},
{B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B},
{B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B},
{B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B},
{B, B, B, B, S, S, S, S, S, S, S, S, S, S, B, B, B, B},
{B, B, B, B, S, S, S, S, S, G, G, G, G, G, S, S, S, S, S, B, B, B, B},
{B, B, B, B, S, S, S, S, S, G, G, G, G, G, S, S, S, S, S, B, B, B, B},
{S, S, S, S, S, S, S, S, S, G, G, G, G, G, S, S, S, S, S, S, S, S, S},
{S, S, S, S, S, S, S, G, G, G, G, G, G, G, G, G, S, S, S, S, S, S, S},
{S, S, S, S, S, S, S, G, G, G, G, G, G, G, G, G, S, S, S, S, S, S, S},
{S, S, S, S, S, S, S, G, G, G, G, G, G, G, G, G, S, S, S, S, S, S, S}
};
}
public void DisplayTheatre(Seat x[][]) {
for (int row = 0; row < x.length; row++) {
for (int col = 0; col < x[row].length; col++) {
System.out.print(x[row][col]);
}
System.out.println();
}
}
}
因此,由于这不起作用,我知道我正在以错误的方式进行操作,我如何能够打印出 Theatre 类的构造函数中的数组?
任何帮助将不胜感激,在此先感谢您。^^