//测试函数放在Booking里面
//Enum PassengerCabin
package systemofAirplane;
public enum PassengerCabin {
头等舱,商务舱,经济舱
}
//Enum Status
package systemofAirplane;
public enum Status {
待审核,审核中,审核通过
}
//Booking.java
package systemofAirplane;
import java.util.Scanner;
public class Booking {
private String initialAddress;
private String destination;
private String startTime;
private String returnTime;
private int population;
private PassengerCabin cabin;
Booking(String initialAddress,String destination,String startTime,String returnTime,int population,String cabin)
{
this.initialAddress=initialAddress;
this.destination=destination;
this.startTime=startTime;
this.returnTime=returnTime;
this.population=population;
this.cabin=Enum.valueOf(PassengerCabin.class, cabin);
}
Booking()
{
this("延边大学","长沙黄花机场","2019/10/31/00:00","2019/10/31/9:30",7,"经济舱");
}
public String getInitialAddress()
{
return initialAddress;
}
public void setInitialAddress(String initialAddress)
{
this.initialAddress=initialAddress;
}
public String getDestination()
{
return destination;
}
public void setDestination(String destination)
{
this.destination=destination;
}
public String getStartTime()
{
return startTime;
}
public void setStartTime(String startTime)
{
this.startTime=startTime;
}
public String getReturnTime()
{
return returnTime;
}
public void setReturnTime(String returnTime)
{
this.returnTime=returnTime;
}
public int getPopulation()
{
return population;
}
public void setPopulation(int num)
{
this.population=num;
}
public PassengerCabin getPassengerCabin()
{
return cabin;
}
public void setPassengerCabin(PassengerCabin cabin)
{
this.cabin=cabin;
}
public String toString()
{
System.out.println("您的机票综合信息如下:");
return ("place of departure:"+initialAddress+"\tdestination:"+destination+"\nstarttime:"+startTime+"\t returntime:"+returnTime+" \nnumber of passenger:"+population+"\nthe type of Cabin:"+cabin);
}
public static void main(String args[])
{
Booking ticket=new Booking();
Scanner input=new Scanner(System.in);
System.out.println("请输入出发地点:");
String initialAddress=input.next();
ticket.setInitialAddress(initialAddress);
System.out.println("请输入终点:");
String destination=input.next();
ticket.setDestination(destination);
System.out.println("请输入出发时间:");
String startTime=input.next();
ticket.setStartTime(startTime);
System.out.println("请输入返回时间:");
String returnTime=input.next();
ticket.setReturnTime(returnTime);
System.out.println("请输入人数:");
int num=input.nextInt();
ticket.setPopulation(num);
System.out.println("请输入客舱类型:");
String passengerCabin=input.next();
ticket.setPassengerCabin(Enum.valueOf(PassengerCabin.class,passengerCabin));
System.out.println("出发地点:\t"+ticket.getInitialAddress());
System.out.println("终点:\t"+ticket.getDestination());
System.out.println("出发时间:\t"+ticket.getStartTime());
System.out.println("返回时间:\t"+ticket.getReturnTime());
System.out.println("人数:\t"+ticket.getPopulation());
System.out.println("客舱\t"+ticket.getPassengerCabin());
System.out.println(ticket.toString());
input.close();
}
}
//AviationRoute.java
package systemofAirplane;
public class AviationRoute
{
private Order information;
private String airline;//航空公司
private String type;//机型
private int personsCapacity;//最大载人数
private int spareDigits;//空余位数
AviationRoute(Order infor,String airline,String type,int capacity,int spareDigits)
{
this.information=infor;
this.airline=airline;
this.type=type;
this.personsCapacity=capacity;
this.spareDigits=spareDigits;
}
AviationRoute(String airline,String type,int capacity,int spareDigits)
{
this.airline=airline;
this.type=type;
this.personsCapacity=capacity;
this.spareDigits=spareDigits;
}
AviationRoute(){
this("中国国际航空公司","大型宽体飞机",330,63);
}
public String getFlightNumber()
{
return information.getFlightNumber();
}
public void setFlightNumber(String flightNumber)
{
information.setFlightNumber(flightNumber);
}
public String getAirline()
{
return airline;
}
public void setAirline(String airline)
{
this.airline=airline;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type=type;
}
public int getPersonsCapacity()
{
return personsCapacity;
}
public void setPersonsCapacity(int capacity)
{
this.personsCapacity=capacity;
}
public int getSpareDigits()
{
return spareDigits;
}
public void setSpareDigits(int spareDigits)
{
this.spareDigits=spareDigits;
}
public String getDepartureTime()
{
return information.getDepartureTime();
}
public void setDepartureTime(String dTime)
{
information.setDepartureTime(dTime);
}
public String getArrivalTime()
{
return information.getArrivalTime();
}
public void setArrivalTime(String aTime)
{
information.setArrivalTime(aTime);
}
}
//Order.java
package systemofAirplane;
public class Order
{
private String orderNumber;
private Status orderStatus;
private String flightNumber;
private String departureTime;
private String arrivalTime;
private int price;
Order(String orderNumber,String orderStatus,String flightNumber,String departureTime,String arrivalTime,int price)
{
this.orderNumber=orderNumber;
this.orderStatus=Enum.valueOf(Status.class,orderStatus);
this.flightNumber=flightNumber;
this.departureTime=departureTime;
this.arrivalTime=arrivalTime;
this.price=price;
}
Order()
{
this("218401131230","待审核","CA1585","2020/01/13/12:30","2020/01/13/14:30",799);
}
public String getOrderNumber()
{
return orderNumber;
}
public void setOrderNumber(String orderNumber)
{
this.orderNumber=orderNumber;
}
public Status getOrderStatus()
{
return orderStatus;
}
public void setOrderStatus(String status)
{
this.orderStatus=Enum.valueOf(Status.class, status);
}
public String getFlightNumber()
{
return flightNumber;
}
public void setFlightNumber(String flightNumber)
{
this.flightNumber=flightNumber;
}
public String getDepartureTime()
{
return departureTime;
}
public void setDepartureTime(String dTime)
{
this.departureTime=dTime;
}
public String getArrivalTime()
{
return arrivalTime;
}
public void setArrivalTime(String aTime)
{
this.arrivalTime=aTime;
}
public int getPrice()
{
return price;
}
public void setPrice(int price)
{
this.price=price;
}
public String toString()
{
return("订单号:"+orderNumber+"\t订单状态:"+orderStatus+"\t航班号:"+flightNumber+"\t起飞时间:"+departureTime+"\t到达时间:"+arrivalTime+"\t价格:"+price);
}
}
//AviationPassenger
package systemofAirplane;
public class AviationPassenger {
private String name;
private String IDNumber;
private String phone;
private String address;
private int credits;
public AviationPassenger(){
this("暂时未输入姓名","4302319990903xxxx","151xxxx9624","延边大学",0);
};
public AviationPassenger(String name,String ID,String string,String address,int credits) {
this.name=name;
this.IDNumber=ID;
this.phone=string;
this.address=address;
this.credits=credits;
}
public String getName()
{
return name;
}
public String getIdNumber()
{
return IDNumber;
}
public String getPhone()
{
return phone;
}
public String getAddress()
{
return address;
}
public int getCredits()
{
return credits;
}
public void setName(String name)
{
this.name=name;
}
public void setIdNumber(String Id)
{
this.IDNumber=Id;
}
public void setPhone(String phone)
{
this.phone=phone;
}
public void setAddress(String address)
{
this.address=address;
}
public void setCredits(int credits)
{
this.credits=credits;
}
public String toString() {
System.out.println("The passenger's information is:");
return ("姓名:"+name+"\t身份证号:"+IDNumber+"\t电话:"+phone+"\t住址:"+address+"\t积分:"+credits);
}
}
//AviationSystemTest
package systemofAirplane;
public class AirplaneSystemTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
//Bus.java
package systemofbus;
import java.util.*;
public class Bus {
String num;
String engine;
int capacity;
int route;
String [] b=new String[10];
Bus() {
num="000";
engine="000";
capacity=0;
route=0;
//System.out.println("construct a Bus!");
}
void Add(Bus bus,String str) {
Scanner sc1=new Scanner(System.in);
System.out.println("input a num of this Bus(three number for example:001(000 represent the System have not bus):");
bus.num=sc1.nextLine();
System.out.println("input a engine number of this Bus(three number for example:001(000 stand for the System have not bus):");
Scanner sc2=new Scanner(System.in);
bus.engine=sc2.nextLine();
System.out.println("input a capacity of this Bus:");
Scanner sc3=new Scanner(System.in);
bus.capacity=sc3.nextInt();
System.out.println("input a route of this Bus:");
Scanner sc4=new Scanner(System.in);
bus.route=sc4.nextInt();
if(str.equals("no"))
{
sc1.close();
sc2.close();
sc3.close();
sc4.close();
}
}
int Delete(Bus bus,int n) {
if(!bus.num.equals("000")) {
bus.num="000";
bus.engine="000";
bus.capacity=0;
bus.route=0;
n--;
System.out.println("Delete a Bus!");
}
else
System.out.println("Not find!!");
return n;
}
void Inquire(Bus bus) {
if(bus.num!="000")
{
System.out.println("Find this Bus!");
System.out.println("The bus's number is "+bus.num);
System.out.println("The bus's engine number is "+bus.engine);
System.out.println("The bus's capacity is "+bus.capacity);
System.out.println("The bus's route is "+bus.route);
}
else
System.out.println("Not have this Bus!");
}
void Change(Bus bus) {
int choice;
System.out.println("input the information that you want to change(1.number,2.engine number,3.setting capacity,4.route):");
Scanner sc=new Scanner(System.in);
choice=sc.nextInt();
if(bus.num.equals("000")||bus.engine.equals("000")||bus.capacity==0||bus.route==0) {
System.out.println("Not find!!");
sc.close();
return;
}
switch(choice){
case 1:
System.out.println("input the number that you want to change(三位数字):");
Scanner sc1=new Scanner(System.in);
bus.num=sc1.nextLine();
sc1.close();
break;
case 2:
System.out.println("input the engine number that you want to change:");
Scanner sc2=new Scanner(System.in);
bus.num=sc2.nextLine();
sc2.close();
break;
case 3:
System.out.println("input the setting capacityies that you want to change:");
Scanner sc3=new Scanner(System.in);
bus.num=sc3.nextLine();
sc3.close();
break;
case 4:
System.out.println("input the route that you want to change:");
Scanner sc4=new Scanner(System.in);
bus.num=sc4.nextLine();
sc4.close();
break;
}
sc.close();
}
public static void main(String[] args){
// TODO Auto-generated method stub
}
}
//BusRoute.java
package systemofbus;
import java.util.List;
import java.util.ArrayList;
import java.util.Date;
//每一个链表实际上就是由多个节点组成的
class Node {
private String data; // 用于保存数据
private Node next; // 用于保存下一个节点
public Node(String data) { // 每一个Node类对象都必须保存有响应的数据
this.data = data;
}
public void setNext(Node next) {
this.next = next;
}
public Node getNext() {
return this.next;
}
public String getData() {
return this.data;
}
// 实现节点的添加:
// 第一次调用(Link):this代表Link.root
// 第二次调用(Node):this代表Link.root.next
// 第三次调用(Node):this代表Link.root.next.next
public void addNode(Node oldNode,Node newNode) {
System.out.println("now:"+oldNode);
if (this.next == null) { // 保存新节点
this.next = newNode;
} else { // 当前节点后面还有节点
this.next.addNode(this.next,newNode); // 当前节点的下一个节点继续保存,这里采用的是递归添加节点
}
System.out.println(oldNode+"=>"+this.next);
}
// 第一次调用(Link):this代表Link.root
// 第二次调用(Node):this代表Link.root.next
// 第三次调用(Node):this代表Link.root.next.next
public void printNode() {
System.out.println("pp:"+this.data);// 输出当前数据
if (this.next != null) { // 如果还有下一个节点,输出下一节点
this.next.printNode(); // 递归打印节点,注意这里的this.next中的this指代
}
}
}
//链表增加节点,输出节点数据
class Link {
private Node root; //新建根节点
public void add (String data){
Node newNode = new Node(data); //链表中新增节点类对象
if(this.root == null ){ // 如果链表还没有任何节点,就添加第一个节点作为根节点
this.root = newNode;
System.out.println("root:"+this.root);
}else{
System.out.println("new:"+newNode);
this.root.addNode(this.root,newNode); //从根节点节点新链接一个节点
}
}
//输出当前节点数据
public void print(){
if( this.root != null ){
this.root.printNode();
}
}
}
public class BusRoute{
private Integer id; // 给每个线路分配一个ID
private String name; // 线路名称
private List<Bus> list; // 线路所包含的汽车
private List<BusRoute>routelist;
public BusRoute(){//无参构造函数
}
public BusRoute(Integer id, String name){
this.id = id;
this.name = name;
this.list = new ArrayList<Bus>();
this.routelist=new ArrayList<BusRoute>();
}
public void setId(Integer id){
this.id = id;
}
public void setName(String name){
this.name = name;
}
public void setBusRouteList(List<BusRoute> routelist){
this.routelist = routelist;
}
public void setList(List<Bus> list){
this.list = list;
}
public String getName(){
return name;
}
public Integer getId(){
return id;
}
public List<Bus> getBusList(){
return list;
}
public List<BusRoute> getBusRouteList(){
return routelist;
}
public boolean isHasThisBus(Bus bus){
for (Bus bus1 :this.getBusList()){
if (bus1.equals(bus)){
return true;
}
}
return false;
}
//增加一条线路
public void addBusRoute(BusRoute route){
boolean flag=true;
for(BusRoute route1: this.getBusRouteList()){
flag=false;
throw new RuntimeException("系统中已存在线路: "+route1);
}
if(flag) {
routelist.add(route);
System.out.println("添加一条路线!!");
}
}
//修改一条线路
public void updateBusRoute(BusRoute route){
//根据route 的id 获取已存在系统中的route
//List route1 = getBusRouteList();
boolean flag=true;
for(BusRoute route1:getBusRouteList()) {
((BusRoute) route1).setName(route.getName());
((BusRoute) route1).setBusRouteList(route.getBusRouteList());
flag=false;
}
if(flag){
throw new RuntimeException("线路id不匹配,无法修改");
}
}
//获取该系统中的线路,根据id获取
public BusRoute getBusRoute(Integer id){
BusRoute route2 = null;
for(BusRoute busroute : this.getBusRouteList()){
if(busroute.getId().equals(id)){
route2 = busroute;
}
}
return route2;
}
//删除一条线路,根据对象删除
public void removeRoute(BusRoute route){
if(!this.getBusRouteList().remove(route)){
throw new RuntimeException(route.getId()+"线路不存在");
}
else {
routelist.remove(route);
System.out.println("删除一条路线!!");
}
}
// 添加汽车,成功返回true
public boolean addBus(Bus bus){
return this.getBusList().add(bus);
}
// 移除汽车,成功返回true
public boolean removeBus(Bus bus){
return this.getBusList().remove(bus);
}
@Override
public String toString(){
return name;
}
}
//BusPassenger.java
package systemofbus;
import java.util.Scanner;
public class BusPassenger {
private String name;
private int age;
private String sex;
private String message;
public BusPassenger(){ //无参构造
}
public BusPassenger(String n,int a,String sex1){
name=n;
age=a;
sex=sex1;
}
public String getName(){
return name;
}
public String getSex() {
return sex;
}
public String getMessage() {
return message;
}
public int getAge(){
return age;
}
void Add(BusPassenger pa,String str) {
Scanner sc1=new Scanner(System.in);
System.out.println("input a name of this passenger:");
pa.name=sc1.nextLine();
System.out.println("input a age of this passenger:");
Scanner sc2=new Scanner(System.in);
pa.age=sc2.nextInt();
System.out.println("input the sex of passengers in this bus:");
Scanner sc3=new Scanner(System.in);
pa.sex=sc3.nextLine();
if(str.equals("no"))
{
sc1.close();
sc2.close();
sc3.close();
}
}
void Delete() {
}
void Inquire() {
}
void Change(BusPassenger pa) {
int choice;
System.out.println("input the information that you want to change(1.name,2.age,3.salary):");
Scanner sc=new Scanner(System.in);
choice=sc.nextInt();
switch(choice){
case 1:
System.out.println("input the name that you want to change:");
Scanner sc1=new Scanner(System.in);
pa.name=sc1.nextLine();
sc1.close();
break;
case 2:
System.out.println("input the age that you want to change:");
Scanner sc2=new Scanner(System.in);
pa.age=sc2.nextInt();
sc2.close();
break;
case 3:
System.out.println("input the sex that you want to change:");
Scanner sc3=new Scanner(System.in);
pa.sex=sc3.nextLine();
sc3.close();
break;
}
sc.close();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
//Employee.java
package systemofbus;
import java.util.Scanner;
public class Employee {
private double salary;
private String name;
private int age;
private String ID;
public Employee(){ //无参构造
}
public Employee(String n,double s,int a){
name=n;
salary=s;
age=a;
}
public String getID() {
return ID;
}
public String getName(){
return name;
}
public double getSalary(){
return salary;
}
public int getAge(){
return age;
}
public void increaseSalary(double number){
double increase=salary*number/100;
salary+=increase;
}
void Add(Employee em,String str) {
Scanner sc1=new Scanner(System.in);
System.out.println("input a name of this Employee:");
em.name=sc1.nextLine();
System.out.println("input a age of this Employee:");
Scanner sc2=new Scanner(System.in);
em.age=sc2.nextInt();
System.out.println("input a capacity of this Employee:");
Scanner sc3=new Scanner(System.in);
em.salary=sc3.nextDouble();
if(str.equals("no"))
{
sc1.close();
sc2.close();
sc3.close();
}
}
void Delete() {
}
void Inquire() {
}
void Change(Employee em) {
int choice;
System.out.println("input the information that you want to change(1.name,2.age,3.salary,4.ID):");
Scanner sc=new Scanner(System.in);
choice=sc.nextInt();
switch(choice){
case 1:
System.out.println("input the name that you want to change:");
Scanner sc1=new Scanner(System.in);
em.name=sc1.nextLine();
sc1.close();
break;
case 2:
System.out.println("input the age that you want to change:");
Scanner sc2=new Scanner(System.in);
em.age=sc2.nextInt();
sc2.close();
break;
case 3:
System.out.println("input the salary that you want to change:");
Scanner sc3=new Scanner(System.in);
em.salary=sc3.nextDouble();
sc3.close();
break;
case 4:
System.out.println("input the ID that you want to change:");
Scanner sc4=new Scanner(System.in);
em.ID=sc4.nextLine();
sc4.close();
break;
}
sc.close();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
//BusSystemTest.java
package systemofbus;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.math.*;
import java.io.*;
public class BusManageSystem {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int i=0;
Bus []bus=new Bus[10];
String str="yes";
for(int k=0;k<10;k++) {
bus[k]=new Bus();
}
while(str.equals("yes")&&i<10) {
bus[i].Add(bus[i],str);
i++;
System.out.println("Do you want to continue to add Bus?(yes/no)");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
try{ //该方法中有个IOExcepiton需要捕获
str = in.readLine();
System.out.println("ReadTest Output:" + str);
}
catch(IOException e){
e.printStackTrace();
}
if(str.equals("yes"))
continue;
else
break;
}
System.out.println("input the sequence number you want to delete(0-9):");
Scanner sc1=new Scanner(System.in);
int d=sc1.nextInt();
i=bus[d].Delete(bus[d],i);
System.out.println("input the sequnece number you want to Inquire(0-9):");
Scanner sc2=new Scanner(System.in);
int k=sc2.nextInt();
//bus[k].Change(bus[k]);
System.out.println("查询一次!!!");
bus[k].Inquire(bus[k]);
System.out.println("Bus System has "+i+" Bus!");
BusRoute []route=new BusRoute[100];
for(int r=0;r<i;r++) {
route[r]=new BusRoute(r,"路线"+r);
route[r].addBusRoute(route[r]);
System.out.print("路线名称:"+route[r].getName());
System.out.print(" 路线ID:"+route[r].getId());
System.out.println(" "+route[r].getBusRouteList());
}
System.out.println("请输入你想要修改的路线:");
Scanner sca=new Scanner(System.in);
int temp=sca.nextInt();
route[temp]=new BusRoute();
// route[temp].updateBusRoute(route[temp]);
System.out.println("请输入公司总员工人数:");
Scanner sc3=new Scanner(System.in);
int employeenum=sc3.nextInt();
Employee []em=new Employee[1000];
for(int r=0;r<employeenum;r++) {
em[r]=new Employee("xxxx",100.0,18);
System.out.print("第"+(r+1)+"位员工名字:"+em[r].getName());
System.out.print(" 第"+(r+1)+"位员工工资:"+((int)(em[r].getSalary()+Math.exp(r))));
System.out.println(" 第"+(r+1)+"位员工年龄: "+(em[r].getAge()+(int)(60*Math.random())));
}
System.out.println("请输入车上总乘客人数:");
Scanner sc4=new Scanner(System.in);
int passengernum=sc4.nextInt();
BusPassenger [] pa=new BusPassenger[1000];
for(int r=0;r<passengernum;r++) {
pa[r]=new BusPassenger("xxxx",18,"未知");
System.out.print("第"+(r+1)+"位乘客名字:"+pa[r].getName());
System.out.print(" 第"+(r+1)+"位乘客年龄:"+(pa[r].getAge()+(int)(80*Math.random())));
System.out.println(" 第"+(r+1)+"位乘客性别: "+pa[r].getSex());
}
sc1.close();
sc2.close();
sc3.close();
sc4.close();
sca.close();
}
}