java订电影票系统

时间:2021-10-31 03:39:07
 public class Test {
public static void main(String[] args) {
BookTicket bookTicket = new BookTicket();
bookTicket.init();
} }
 import java.util.Scanner;

 public class BookTicket {   //主界面类

     Movie[] movie = new Movie[3];
LoginReg loginReg = new LoginReg();
Scanner input = new Scanner(System.in); void movieInformation()// 内部电影信息
{
movie[0] = new Movie();
movie[0].number = "S1124";
movie[0].movieName = "乱世佳人";
movie[0].movieTime = "2013.11.24";
movie[0].moviePrice = 70;
movie[1] = new Movie();
movie[1].number = "S1125";
movie[1].movieName = "青春如期";
movie[1].movieTime = "2013.11.25";
movie[1].moviePrice = 80;
movie[2] = new Movie();
movie[2].number = "S1126";
movie[2].movieName = "让子弹飞";
movie[2].movieTime = "2013.11.26";
movie[2].moviePrice = 90;
} void interFace()// 订票界面
{ System.out.println("\t\t\t∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞");
System.out.println("\t\t\t 订 票 系 统");
System.out.println("\t\t\t∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞"); System.out
.println("------------------------------------------------------------------------------");
System.out.println("电影编号\t\t电影名\t\t上映时间\t\t电影票价");
System.out.println(movie[0].number + "\t\t" + movie[0].movieName + "\t\t"+ movie[0].movieTime + "\t" + "$" + movie[0].moviePrice);
System.out.println(movie[1].number + "\t\t" + movie[1].movieName + "\t\t"+ movie[1].movieTime + "\t" + "$" + movie[1].moviePrice);
System.out.println(movie[2].number + "\t\t" + movie[2].movieName + "\t\t"+ movie[2].movieTime + "\t" + "$" + movie[2].moviePrice);
System.out
.println("------------------------------------------------------------------------------");
} void login()// 登陆、注册
{
System.out.println("1.登陆\t\t2.注册");
Scanner input = new Scanner(System.in);
int logReg = input.nextInt();
switch (logReg) {
case 1:
if (loginReg.login() == 0)
login();
break;
case 2:
loginReg.reg();
login();
break;
default:
System.out.println("输入错误");
login();
}
} void booking()// 订票
{
boolean con = true;
int index = 0;
int[] flag = { -1, -1, -1 };
do {
System.out.println("\t\t欢迎订票");
System.out.println("请输入电影编号(注意字母大写)");
String odd = input.next();
for (int i = 0; i < movie.length; i++) {
if (movie[i].number.equals(odd)) {
flag[index] = i; break;
}
}
if (flag[index] == -1) {
System.out.println("\t\t编号输入错误(找不到您要的电影)");
} else {
System.out.println("\t\t订票成功");
System.out.println("电影编号\t电影名\t\t上映时间\t\t电影票价");
System.out.println(movie[flag[index]].number + "\t\t"
+ movie[flag[index]].movieName + "\t"
+ movie[flag[index]].movieTime + "\t\t" + "$"
+ movie[flag[index]].moviePrice);
index++;
}
System.out.println("是否需要继续订票(Y/N)");
String yesNo = input.next();
if (yesNo.equals("N"))
con = false;
if (index >= 3) {
System.out.println("已经没有可预订的票");
con = false;
}
} while (con);
int add = 0;
int sign = 0;
for (index = 0; index < 3; index++) {
if (flag[index] != -1) {
add += movie[flag[index]].moviePrice;
sign++;
}
}
System.out.println("你一共订了" + sign + "张票" + "一共¥" + add + "元");
} void init() {
movieInformation();// 电影信息录入
interFace();// 界面
login();// 用户登陆、注册
booking();// 订票
} }
 import java.util.Scanner;
public class LoginReg { //登陆,注册类
final int INIT = 1024;
User[] user = new User[INIT];
Scanner input = new Scanner(System.in); void reg()//用户注册
{
int flag = 0;
System.out.println("\t欢 迎 注 册");
System.out.println("用户名");
for(int i = 0;i < INIT;i++)
{
if(user[i]==null)
{
user[i] = new User();
user[i].name = input.next();
flag = i;
break;
}
}
System.out.println("密码");
user[flag].password = input.next();
System.out.println("\t恭 喜 您!注 册 成 功");
}
int login()//用户登陆
{
int flag = 0;
System.out.println("\t欢 迎 登 陆");
System.out.println("用户名");
String n1 = input.next();
System.out.println("密码");
String n2 = input.next();
for(int i = 0;i < INIT;i++)
{
if(user[i]!=null)
{
if(user[i].name.equals(n1) && user[i].password.equals(n2))
{
flag = 1;
break;
}
}
}
switch(flag)
{
case 0:
System.out.println("登陆失败");
System.out.println("是否重新登录(Y/N)");
String instr = input.next();
if(instr.equals("Y"))
login();
break;
case 1:
System.out.println("登陆成功");
break; }
return flag; }
}
 public class User {  //用户类
String name;// 用户名
String password;//密码
}
 public class Movie { //电影类
String number;
String movieName;
String movieTime;
int moviePrice;
}