![]() |
#2
疯狂的小a2018-05-09 14:13
![]() import java.util.Scanner; /** * @author niyite * */ /** * * 要求: (2) 对Employee模块进行扩展:派生manager类,manager具有职务、管理部门、职责等特性。 * (3)对Route线路管理模块进行扩展:Route类派生出一个Local类和LongDistance类,Local类负责市内或近郊线路; * LongDistance类负责长途客运。自行设计两个子类属性和相关操作。这两个类里都有一个Bus类对象作为数据成员, * 用于记录运行于这两种公交线路的所有Bus信息。 (4) 定义测试类以继承的方式实现以上模块。 * */ public class Test { public static void main(String args[]) { Scanner scn = new Scanner(System.in); System.out.println("请选择功能"); int t = 6, i, m, n; // Bus bus[] = new Bus[2]; Route route[] = new Route[2]; Employee employee[] = new Employee[2]; Passenger passenger[] = new Passenger[2]; // for (i = 0; i <= 1; i++) { bus[i] = new Bus(); route[i] = new Route(); employee[i] = new Employee(); passenger[i] = new Passenger(); } // while (t != 0) { System.out.println("1.车辆管理"); System.out.println("2.线路管理"); System.out.println("3.员工管理"); System.out.println("4.乘客管理"); System.out.println("5.输出信息"); t = scn.nextInt(); // switch (t) { // case 1: { System.out.println("1.添加"); System.out.println("2.修改"); System.out.println("3.删除"); m = scn.nextInt(); switch (m) {// case 1: { for (i = 0; i <= 1; i++) if (bus[i].type == null) break; if (i != 2) bus[i].Scn(); else System.out.println("信息已满"); } break; // 添加车辆信息 case 2: { n = scn.nextInt(); if (bus[n - 1].type == null) System.out.println("所选对象为空"); else bus[n - 1].Scn(); } break; // 修改车辆信息 case 3: { n = scn.nextInt(); bus[n - 1].del(); } break; } // 删除车辆信息 } break; // 车辆管理 case 2: { System.out.println("1.添加"); System.out.println("2.修改"); System.out.println("3.删除"); m = scn.nextInt(); switch (m) {// case 1: { for (i = 0; i <= 1; i++) if (route[i].station == null) break; if (i != 2) route[i].Scn(); else System.out.println("信息已满"); } break; // 添加线路信息 case 2: { n = scn.nextInt(); if (route[n - 1].station == null) System.out.println("所选对象为空"); else route[n - 1].Scn(); } break; // 修改线路信息 case 3: { n = scn.nextInt(); route[n - 1].del(); } break; // 删除线路信息 } break; } // 线路管理 case 3: { System.out.println("1.添加"); System.out.println("2.修改"); System.out.println("3.删除"); m = scn.nextInt(); switch (m) {// case 1: { for (i = 0; i <= 1; i++) if (employee[i].name == null) break; if (i != 2) employee[i].Scn(); else System.out.println("信息已满"); } break; // 添加员工信息 case 2: { n = scn.nextInt(); if (employee[n - 1].name == null) System.out.println("所选对象为空"); else employee[n - 1].Scn(); } break; // 修改员工信息 case 3: { n = scn.nextInt(); employee[n - 1].del(); } break; // 删除员工信息 } break; } // 员工管理 case 4: { System.out.println("1.添加"); System.out.println("2.修改"); System.out.println("3.删除"); m = scn.nextInt(); switch (m) {// case 1: { for (i = 0; i <= 1; i++) if (passenger[i].name == null) break; if (i != 2) passenger[i].Scn(); else System.out.println("信息已满"); } break; // 添加乘客信息 case 2: { n = scn.nextInt(); if (passenger[n - 1].name == null) System.out.println("所选对象为空"); else passenger[n - 1].Scn(); } break; // 修改乘客信息 case 3: { n = scn.nextInt(); passenger[n - 1].del(); } break; // 删除乘客信息 } break; } // 乘客管理 case 5: { for (i = 0; i <= 1; i++) { System.out.println("线路" + (i + 1)); bus[i].Prn(); route[i].Prn(); employee[i].Prn(); passenger[i].Prn(); } } } } } } class Bus { Scanner scn = new Scanner(System.in); String type; int number; int route; int capacity; void Scn() { System.out.println("请依次输入车辆的线路类型,车号,线路号,载客量,以回车分隔"); type = scn.nextLine(); number = scn.nextInt(); route = scn.nextInt(); capacity = scn.nextInt(); } void Prn() { System.out.println("线路类型:" + type); System.out.println("车号:" + number); System.out.println("线路号:" + route); System.out.println("载客量:" + capacity); } void del() { type = null; number = 0; route = 0; capacity = 0; } } class Local extends Route { } class Distance extends Route { } class Route { Scanner scn = new Scanner(System.in); int StopNo; String station; String destination; String RunTime; void Scn() { System.out.println("请依次输入线路的站数,始发站,终点站,运行时间,以回车分隔"); StopNo = scn.nextInt(); scn.nextLine(); station = scn.nextLine(); destination = scn.nextLine(); RunTime = scn.nextLine(); } void Prn() { System.out.println("站数:" + StopNo); System.out.println("始发站:" + station); System.out.println("终点站:" + destination); System.out.println("运行时间:" + RunTime); } void del() { StopNo = 0; station = null; destination = null; RunTime = null; } } class Employee { Scanner scn = new Scanner(System.in); String name; int ID; int age; double salary; String department; void Scn() { System.out.println("请依次输入员工的姓名,工号,年龄,工资,部门,以回车分隔"); name = scn.nextLine(); ID = scn.nextInt(); age = scn.nextInt(); salary = scn.nextDouble(); scn.nextLine(); department = scn.nextLine(); } void Prn() { System.out.println("姓名:" + name); System.out.println("工号:" + ID); System.out.println("年龄:" + age); System.out.println("工资:" + salary); System.out.println("部门:" + department); } void del() { name = null; ID = 0; age = 0; salary = 0; department = null; } } class Manager extends Employee { String position, duty, manage; } class Passenger { Scanner scn = new Scanner(System.in); String name; String sex; int age; String message; void Scn() { System.out.println("请依次输入乘客的姓名,性别,年龄,信息,以回车分隔"); name = scn.nextLine(); sex = scn.nextLine(); age = scn.nextInt(); message = scn.nextLine(); } void Prn() { System.out.println("姓名:" + name); System.out.println("性别:" + sex); System.out.println("年龄:" + age); System.out.println("信息:" + message); } void del() { name = null; sex = null; age = 0; message = null; } } 你debug运行一下,太长了,没时间给你细看 ![]() |
代码如下:import java.util.Scanner;
public class Test {
public static void main(String args[])
{
Scanner scn=new Scanner(System.in);
System.out.println("请选择功能");
int t=6,i,m,n;
//
Bus bus[]=new Bus[2];
Route route[]=new Route[2];
Employee employee[]=new Employee[2];
Passenger passenger[]=new Passenger[2];
//
for(i=0;i<=1;i++)
{bus[i]=new Bus();
route[i]=new Route();
employee [i]=new Employee();
passenger[i]=new Passenger();}
//
while(t!=0) {
System.out.println("1.车辆管理");
System.out.println("2.线路管理");
System.out.println("3.员工管理");
System.out.println("4.乘客管理");
System.out.println("5.输出信息");
t=scn.nextInt();
//
switch(t) {
//
case 1:{System.out.println("1.添加");
System.out.println("2.修改");
System.out.println("3.删除");
m=scn.nextInt();
switch(m)
{//
case 1:{for(i=0;i<=1;i++)
if(bus[i].type==null) break;
if(i!=2) bus[i].Scn();
else System.out.println("信息已满");}break;
//添加车辆信息
case 2:{n=scn.nextInt();
if(bus[n-1].type==null)System.out.println("所选对象为空");
else bus[n-1].Scn();}break;
//修改车辆信息
case 3:{n=scn.nextInt();
bus[n-1].del();}break;
}
//删除车辆信息
}break;
//车辆管理
case 2:{System.out.println("1.添加");
System.out.println("2.修改");
System.out.println("3.删除");
m=scn.nextInt();
switch(m)
{//
case 1:{for(i=0;i<=1;i++)
if(route[i].station==null) break;
if(i!=2) route[i].Scn();
else System.out.println("信息已满");}break;
//添加线路信息
case 2:{n=scn.nextInt();
if(route[n-1].station==null)System.out.println("所选对象为空");
else route[n-1].Scn();}break;
//修改线路信息
case 3:{n=scn.nextInt();
route[n-1].del();}break;
//删除线路信息
}break;
}
//线路管理
case 3:{System.out.println("1.添加");
System.out.println("2.修改");
System.out.println("3.删除");
m=scn.nextInt();
switch(m)
{//
case 1:{for(i=0;i<=1;i++)
if(employee[i].name==null) break;
if(i!=2) employee[i].Scn();
else System.out.println("信息已满");}break;
//添加员工信息
case 2:{n=scn.nextInt();
if(employee[n-1].name==null)System.out.println("所选对象为空");
else employee[n-1].Scn();}break;
//修改员工信息
case 3:{n=scn.nextInt();
employee[n-1].del();}break;
//删除员工信息
}
break;}
//员工管理
case 4:{
System.out.println("1.添加");
System.out.println("2.修改");
System.out.println("3.删除");
m=scn.nextInt();
switch(m)
{//
case 1:{for(i=0;i<=1;i++)
if(passenger[i].name==null) break;
if(i!=2) passenger[i].Scn();
else System.out.println("信息已满");}break;
//添加乘客信息
case 2:{n=scn.nextInt();
if(passenger[n-1].name==null)System.out.println("所选对象为空");
else passenger[n-1].Scn();}break;
//修改乘客信息
case 3:{n=scn.nextInt();
passenger[n-1].del();}break;
//删除乘客信息
}
break;
}
//乘客管理
case 5:{
for(i=0;i<=1;i++)
{System.out.println("线路"+(i+1));
bus[i].Prn();
route[i].Prn();
employee[i].Prn();
passenger[i].Prn();
}
}
}
}
}
}
class Bus{Scanner scn=new Scanner(System.in);
String type;
int number;
int route;
int capacity;
void Scn() {System.out.println("请依次输入车辆的线路类型,车号,线路号,载客量,以回车分隔");
type=scn.nextLine();
number=scn.nextInt();
route=scn.nextInt();
capacity=scn.nextInt();}
void Prn(){System.out.println("线路类型:"+type);
System.out.println("车号:"+number);
System.out.println("线路号:"+route);
System.out.println("载客量:"+capacity);}
void del()
{type=null;number=0;route=0;capacity=0;}
}
class Route{
Scanner scn=new Scanner(System.in);
int StopNo;
String station;
String destination;
String RunTime;
void Scn() {System.out.println("请依次输入线路的站数,始发站,终点站,运行时间,以回车分隔");
StopNo=scn.nextInt();
scn.nextLine();
station=scn.nextLine();
destination=scn.nextLine();
RunTime=scn.nextLine();}
void Prn(){
System.out.println("站数:"+StopNo);
System.out.println("始发站:"+station);
System.out.println("终点站:"+destination);
System.out.println("运行时间:"+RunTime);
}
void del()
{StopNo=0;station=null;destination=null;RunTime=null;}
public class Route extends Local{
}
public class Route extends Distance{
}
}
class Employee{
Scanner scn=new Scanner(System.in);
String name;
int ID;
int age;
double salary;
String department;
void Scn() {System.out.println("请依次输入员工的姓名,工号,年龄,工资,部门,以回车分隔");
name=scn.nextLine();
ID=scn.nextInt();
age=scn.nextInt();
salary=scn.nextDouble();
scn.nextLine();
department=scn.nextLine();}
void Prn(){
System.out.println("姓名:"+name);
System.out.println("工号:"+ID);
System.out.println("年龄:"+age);
System.out.println("工资:"+salary);
System.out.println("部门:"+department);
}
void del()
{name=null;ID=0;age=0;salary=0;department=null;}
public class Employee extends manager{
String position,duty,manage department;
}
}
class Passenger{
Scanner scn=new Scanner(System.in);
String name;
String sex;
int age;
String message;
void Scn() {System.out.println("请依次输入乘客的姓名,性别,年龄,信息,以回车分隔");
name=scn.nextLine();
sex=scn.nextLine();
age=scn.nextInt();
scn.nextLine();
message=scn.nextLine();}
void Prn(){
System.out.println("姓名:"+name);
System.out.println("性别:"+sex);
System.out.println("年龄:"+age);
System.out.println("信息:"+message);
}
void del()
{name=null;sex=null;age=0;message=null;}
}
要求: (2) 对Employee模块进行扩展:派生manager类,manager具有职务、管理部门、职责等特性。
(3) 对Route线路管理模块进行扩展:Route类派生出一个Local类和LongDistance类,Local类负责市内或近郊线路;LongDistance类负责长途客运。自行设计两个子类属性和相关操作。这两个类里都有一个Bus类对象作为数据成员,用于记录运行于这两种公交线路的所有Bus信息。
(4) 定义测试类以继承的方式实现以上模块。