服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - Java实现电影院订票系统代码

Java实现电影院订票系统代码

2021-02-07 12:14笑哼 Java教程

这篇文章主要介绍了Java实现电影院订票系统代码,代码实现了界面类登录注册类,用户类等,具有一定参考价值,需要的朋友可以参考下。

程序是为了方便用户使用的,因此实现图形化界面的程序编写是所有编程语言发展的必然趋势。。。但是由于时间原因,小编并未在代码中添加可视化图形界面,有兴趣的朋友可自行添加。Java实现电影院订票系统代码

可参阅:Java图形化界面设计之容器(JFrame)详解

演示结果:

Java实现电影院订票系统代码

下面是具体实现代码:

?
1
2
3
4
5
6
public class Test {
    public static void main(String[] args) {
        BookTicket bookTicket = new BookTicket();
        bookTicket.init();
    }
}

BookTicket主界面类

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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 = "雷神3:诸神黄昏";
        movie[0].movieTime = "2017-11-03大陆上映";
        movie[0].moviePrice = 70;
        movie[1] = new Movie();
        movie[1].number = "S1125";
        movie[1].movieName = "全球风暴";
        movie[1].movieTime = "2017-10-27大陆上映";
        movie[1].moviePrice = 80;
        movie[2] = new Movie();
        movie[2].number = "S1126";
        movie[2].movieName = "东方快车谋杀案";
        movie[2].movieTime = "2017-11-10大陆上映";
        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();
        // 订票
    }
}

登陆,注册类

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
    }
}

用户类

?
1
2
3
4
public class User { //用户类
 String name;// 用户名
 String password;//密码
 }

电影类

?
1
2
3
4
5
6
public class Movie { //电影类
 String number;
 String movieName;
 String movieTime;
 int moviePrice;
 }

结束。

以上就是本文关于Java实现电影院订票系统代码的全部内容,希望对大家有所帮助。如有不足之处,欢迎留言指出。

原文链接:http://www.cnblogs.com/xh0102/p/5693265.html

延伸 · 阅读

精彩推荐