package yw;
import java.util.Scanner;
public class Cinema {
//电影数组
Movie[] movies;
//放映厅数组
Room[] rooms;
Scanner input = new Scanner(System.in);
//初始化数据
public void initial() {
movies = new Movie[6];
rooms = new Room[3];
for (int i = 0; i < rooms.length; i++) {
Room room = new Room();
room.no = (i + 1);
room.initialRoom();
rooms[i] = room;
}
}
//新增电影
public boolean addMovie() {
boolean result = false;
for (int i = 0; i < movies.length; i++) {
if (movies[i] == null) {
Movie movie = new Movie();
System.out.print("请输入电影的名称:");
movie.name = input.next();
System.out.print("请输入电影的类型");
movie.type = input.next();
System.out.print("请输入电影的主演");
movie.actor = input.next();
System.out.print("请输入电影的价格");
movie.price = input.nextDouble();
movies[i] = movie;
result = true;
break;
}
}
return result;
}
//所有电影信息
public void showAllMovie() {
System.out.println("电影名称\t\t电影类型\t\t电影主演\t\t电影价格");
for (Movie movie : movies) {
if (movies != null) {
System.out.println(movie);
}
}
}
//放映室信息
public void showRoomsInfo() {
for (int i = 0; i < rooms.length; i++) {
if (rooms[i].movie != null) {
System.out.println(rooms[i]);
}
}
}
//查找电影
public Movie findMovie(String name) {
Movie movie = null;
for (int i = 0; i < movies.length; i++) {
if (movies[i] != null) {
if (name.equals(movies[i].name)) {
movie = movies[i];
break;
}
}
}
return movie;
}
//电影上映
public boolean setMovieRoom() {
Scanner input = new Scanner(System.in);
boolean result = false;
System.out.println("放映室设置播放的影片");
System.out.print("请输入放映室编号");
int roomNO = input.nextInt();
System.out.print("请输入放映影片的名称:");
String playName = input.next();
System.out.print("请输入放映影片的时间:");
String playTime = input.next();
Room room = rooms[roomNO - 1];
if (room.movie == null) {
room.initialRoom();
room.movie = findMovie(playName);
room.time = playTime;
result = true;
} else {
System.out.println("该放映室已有电影播放!");
result = false;
}
return result;
}
//售卖
public boolean saleTicket() {
boolean result = false;
System.out.println("电影院放映信息如下:");
showRoomsInfo();
System.out.println("请输入要观看的放映室编号:");
int roomNO = input.nextInt();
if (rooms[roomNO - 1].movie != null && roomNO <= rooms.length) {
rooms[roomNO - 1].showSeats();
System.out.println("请输入座位号:");
int seatNo = input.nextInt();
boolean res = rooms[roomNO - 1].setSaleSeat(seatNo);
if (res) {
System.out.println("购票成功");
System.out.println("打印小票,信息如下:");
System.out.println("--------------------");
System.out.println("电影" + rooms[roomNO - 1].movie.name);
System.out.println("价格" + rooms[roomNO - 1].movie.price);
System.out.println("播放室编号" + roomNO + "\t座位号:" + seatNo);
System.out.println("播放时间:" + rooms[roomNO - 1].time);
result = true;
} else {
System.out.println("购票失败");
}
}
return result;
}
}
|