功能介绍
通过控制台界面交互,主要实现了乘客购票以及退票流程,管理员对航班信息的管理。
界面如下:
项目结构介绍
- 所有文件如下
说明:其中entity包下放了Flight、Order、User三个实体类,Data是整个项目存放的数据(通过ArrayList来存储数据,没有使用数据库)
enumration包下存放了用户vip等级信息相关内容
Main是程序的主入口
service包下是相关业务的实现
util包下是对service中对数据操作的实现(模拟进行持久化),以及其他的一些功能实现
项目代码
Main
主要以switch做了一个选择界面,选的相应功能调用service函数
package main;
import entity.Data;
import service.FlightService;
import service.Impl.FlightServiceImpl;
import service.Impl.OrderServiceImpl;
import service.Impl.UserServiceImpl;
import service.OrderService;
import service.UserService;
import util.Impl.UserUtilImpl;
import util.UserUtil;
import java.util.Scanner;
/**
* @author 爱看星星的猪
* @description
*/
//系统的主入口
public class Main {
static FlightService flightService=new FlightServiceImpl();
static OrderService orderService=new OrderServiceImpl();
static UserService userService=new UserServiceImpl();
static Integer status=Data.getUser().getStatus();
public static void main(String[] args) {
//初始化一些数据
flightService.initFlight();
userService.initUser();
Scanner scanner = new Scanner(System.in);
boolean exit = false;
while (!exit) {
System.out.println("********************欢迎使用机票预定系统!************************");
System.out.println("请选择需要的功能:");
System.out.println("1.登录 2.注册 3.机票信息添加 4.机票信息管理 5.用户查询航线信息");
System.out.println("6.用户购票 7.会员等级 8.用户退票 9.退出");
System.out.println("****************************************************************");
String input=scanner.next();
try{
Integer choice =Integer.valueOf(input);
switch (choice) {
case 1:
System.out.println("进入登录功能");
userService.login();
status=Data.getUser().getStatus();
break;
case 2:
System.out.println("进入注册功能");
userService.register();
break;
case 3:
//检查登录状态
if (status!=null){
if (status.equals(0)){
System.out.println("你的账号已被禁用!");
} else if (status.equals(2)) {
System.out.println("进入机票信息添加功能");
flightService.addFlightInfo(1);
} else {
System.out.println("你没有权限进行操作");
}
}else {
System.out.println("请先登录!");
}
break;
case 4:
if (status!=null){
if (status.equals(0)){
System.out.println("你的账号已被禁用!");
} else if (status.equals(2)) {
System.out.println("进入机票信息管理功能");
flightService.flightManage();
} else {
System.out.println("你没有权限进行操作");
}
}else {
System.out.println("请先登录!");
}
break;
case 5:
if (status!=null){
if (status.equals(0)){
System.out.println("你的账号已被禁用!");
}else {
System.out.println("进入用户查询航线信息功能");
flightService.findFlight();
}
}else {
System.out.println("请先登录!");
}
break;
case 6:
if (status!=null){
if (status.equals(0)){
System.out.println("你的账号已被禁用!");
}else {
System.out.println("进入用户购票功能");
orderService.buy();
}
}else {
System.out.println("请先登录!");
}
break;
case 7:
if (status!=null){
if (status.equals(0)){
System.out.println("你的账号已被禁用!");
}else {
System.out.println("进入会员等级功能");
userService.showVip();
}
}else {
System.out.println("请先登录!");
}
break;
case 8:
if (status!=null){
if (status.equals(0)){
System.out.println("你的账号已被禁用!");
}else {
System.out.println("进入用户退票功能");
orderService.refund();
}
}else {
System.out.println("请先登录!");
}
break;
case 9:
exit=true;
break;
default:
System.out.println("输入不合法,请重新输入!");
break;
}
}catch (NumberFormatException e){
System.out.println("请输入正确的数字序号!");
}
}
System.out.println("退出系统!");
}
}
entity
Flight
航班类:记录航班信息
package entity;
import java.time.LocalDateTime;
/**
* @author 爱看星星的猪
* @description
*/
public class Flight {
private Long flightId;
private String company;
private Double price;
private Integer residueTicket;
private String startAddress;
private String endAddress;
private LocalDateTime startTime;
private LocalDateTime endTime;
public Flight(Long id,String company, Double price, Integer residueTicket, String startAddress, String endAddress, LocalDateTime startTime, LocalDateTime endTime) {
this.flightId=id;
this.company = company;
this.price = price;
this.residueTicket = residueTicket;
this.startAddress = startAddress;
this.endAddress = endAddress;
this.startTime = startTime;
this.endTime = endTime;
}
public Flight(String company, Double price, Integer residueTicket, String startAddress, String endAddress, LocalDateTime startTime, LocalDateTime endTime) {
this.setFlightId((Long) System.currentTimeMillis());
this.company = company;
this.price = price;
this.residueTicket = residueTicket;
this.startAddress = startAddress;
this.endAddress = endAddress;
this.startTime = startTime;
this.endTime = endTime;
}
public Flight() {
}
public Long getFlightId() {
return flightId;
}
public void setFlightId(Long flightId) {
this.flightId = flightId;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
publ
标签:status,机票,String,System,else,预定,println,Java,out
From: https://blog.csdn.net/Liang_z_/article/details/140399542