求个大哥帮帮忙
1新增电影入院2查询电影信息
3电影放映设置
4电影票实时销售 给你改好了。 压缩包里是我的源码。。。 package yw;
import java.util.Scanner;
public class Menu {
public int startMenu() {
Scanner input = new Scanner(System.in);
System.out.println("----------------------------");
System.out.println("1.新增电影");
System.out.println("2.查看电影");
System.out.println("3.放映设置");
System.out.println("4.影票销售");
System.out.println("0.退出系统");
System.out.println("----------------------------");
System.out.print("请选择输入");
int choose = input.nextInt();
return choose;
}
public void startRun() {
Scanner input = new Scanner(System.in);
System.out.println("欢迎进入影院售票系统!");
Menu menu = new Menu();
Cinema cinema = new Cinema();
cinema.initial();
int choose = 0;
while (true) {
choose = menu.startMenu();
switch (choose) {
case 1:
cinema.addMovie();
break;
case 2:
cinema.showAllMovie();
break;
case 3:
cinema.setMovieRoom();
break;
case 4:
cinema.saleTicket();
break;
default:
System.out.println("谢谢使用!再见!");
System.exit(0);
break;
}
System.out.println("输入r返回主菜单");
if (!"r".equals(input.next())) {
System.out.println("输入错误!程序结束!");
break;
}
}
}
}
package yw;
import java.util.Scanner;
public class Movie {
//电影名称
String name;
//电影类型
String type;
//电影主演
String actor;
//电影价格
double price;
public String toString() {
return name + "\t\t" + type + "\t\t" + actor + "\t\t" + price;
}
} 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;
rooms = new Room;
for (int i = 0; i < rooms.length; i++) {
Room room = new Room();
room.no = (i + 1);
room.initialRoom();
rooms = room;
}
}
//新增电影
public boolean addMovie() {
boolean result = false;
for (int i = 0; i < movies.length; i++) {
if (movies == 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 = 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.movie != null) {
System.out.println(rooms);
}
}
}
//查找电影
public Movie findMovie(String name) {
Movie movie = null;
for (int i = 0; i < movies.length; i++) {
if (movies != null) {
if (name.equals(movies.name)) {
movie = movies;
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;
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.movie != null && roomNO <= rooms.length) {
rooms.showSeats();
System.out.println("请输入座位号:");
int seatNo = input.nextInt();
boolean res = rooms.setSaleSeat(seatNo);
if (res) {
System.out.println("购票成功");
System.out.println("打印小票,信息如下:");
System.out.println("--------------------");
System.out.println("电影" + rooms.movie.name);
System.out.println("价格" + rooms.movie.price);
System.out.println("播放室编号" + roomNO + "\t座位号:" + seatNo);
System.out.println("播放时间:" + rooms.time);
result = true;
} else {
System.out.println("购票失败");
}
}
return result;
}
}
package yw;
public class Main {
public static void main(String[] args) {
Menu menu = new Menu();
menu.startRun();
}
} 本帖最后由 slience_缄默 于 2020-11-17 16:07 编辑
还有个类死活发不出去,是不是系统认为我灌水了{:10_257:}{:10_257:}{:10_257:}
package yw;
public class Room {
//播放室编号
int no;
//播放电影
Movie movie;
//播放时间
String time;
//座位数
int[] seats=new int;
//初始化座位号
public void initialRoom() {
for (int i=0;i<seats.length;i++) {
seats=i+1;
}
}
//展示座位信息
public void showSeats() {
System.out.println(no+"号播放室的座位信息如下:");
for (int i=0;i<seats.length;i++) {
if (seats==0) {
System.out.print("无"+"\t");
} else {
System.out.print(seats+"\t");
}
if ((i+1)%7==0) {
System.out.println();
}
}
}
//购票
public boolean setSaleSeat(int i) {
boolean result=false;
if (seats==0) {
return false;
} else {
seats=0;
return true;
}
}
public int getSeatsNum() {
int num=0;
for (int seat:seats) {
if (seat!=0) {
num++;
}
}
return num;
}
public String toString() {
return no+"\t\t"+movie.name+"\t\t"+time+"\t\t"+getSeatsNum();
}
}
slience_缄默 发表于 2020-11-17 16:05
还有个类死活发不出去,是不是系统认为我灌水了
nice 呀 谢谢老哥 slience_缄默 发表于 2020-11-17 16:05
还有个类死活发不出去,是不是系统认为我灌水了
但是我原来到底是哪里错了,能帮忙指出来吗? 温木zou 发表于 2020-11-18 13:48
但是我原来到底是哪里错了,能帮忙指出来吗?
就是在你原有的代码上改的,有参数错的,有true写错的,还有方法放哪里也是错的,你对比下你的原有代码就好了 slience_缄默 发表于 2020-11-18 14:18
就是在你原有的代码上改的,有参数错的,有true写错的,还有方法放哪里也是错的,你对比下你的原有代码就 ...
{:10_255:}这是错很多的意思吗。心累Java这玩意儿真难
页:
[1]