皮卡亿千万
2015-03-07 17:14
//Vehicle.java package Vehicle; public class Bus extends Vehicle { private int busload; public Bus() { // TODO Auto-generated constructor stub super(); this.busload = 0; } public Bus(int id, String name, int dailyCost,int busload) { super(id, name, dailyCost); this.busload = busload; // TODO Auto-generated constructor stub } public int getBusload() { return busload; } public void setBusload(int busload) { this.busload = busload; } void show(){ System.out.println("序号:" + getId() + " | 型号: " + getName() + " | 价格: " + getDailyCost() + "元/天 | 载客量: " + getBusload() + "人"); } } //Bus.java package Vehicle; public class Bus extends Vehicle { private int busload; public Bus() { // TODO Auto-generated constructor stub super(); this.busload = 0; } public Bus(int id, String name, int dailyCost,int busload) { super(id, name, dailyCost); this.busload = busload; // TODO Auto-generated constructor stub } public int getBusload() { return busload; } public void setBusload(int busload) { this.busload = busload; } void show(){ System.out.println("序号:" + getId() + " | 型号: " + getName() + " | 价格: " + getDailyCost() + "元/天 | 载客量: " + getBusload() + "人"); } } //Truck.java package Vehicle; public class Truck extends Vehicle { private double burden; public Truck() { // TODO Auto-generated constructor stub super(); burden = 0; } public Truck(int id, String name, int dailyCost,double burden) { super(id, name, dailyCost); // TODO Auto-generated constructor stub this.burden = burden; } public double getBurden() { return burden; } public void setBurden(double burden) { this.burden = burden; } @Override void show() { // TODO Auto-generated method stub System.out.println("序号:" + getId() + " | 型号: " + getName() + " | 价格: " + getDailyCost() + "元/天 | 载货量: " + getBurden() + "吨"); } } //Pickup.java package Vehicle; public class Pickup extends Vehicle { private int busload; private double burden; public Pickup() { // TODO Auto-generated constructor stub super(); busload = 0; burden = 0; } public Pickup(int id, String name, int dailyCost,int busload,double burden) { super(id, name, dailyCost); // TODO Auto-generated constructor stub this.burden = burden; this.busload = busload; } public int getBusload() { return busload; } public void setBusload(int busload) { this.busload = busload; } public double getBurden() { return burden; } public void setBurden(double burden) { this.burden = burden; } @Override void show() { // TODO Auto-generated method stub System.out.println("序号:" + getId() + " | 型号: " + getName() + " | 价格: " + getDailyCost() + "元/天 | 载客量: " + getBusload() + "人 | 载货量: " + getBurden() + "吨"); } } //Interaction.java package Vehicle; import java.util.Scanner; public class Interaction { private Vehicle[] veh = new Vehicle[6]; private int selectId = -1; public Vehicle[] getVeh() { return veh; } public void setVeh(Vehicle[] veh) { this.veh = veh; } public Interaction() { // TODO Auto-generated constructor stub veh[0] = new Bus(1,"公交车",1200,45); veh[1] = new Bus(2,"小汽车",500,4); veh[2] = new Pickup(3,"小皮卡",400,2,1); veh[3] = new Pickup(4,"大皮卡",800,4,4); veh[4] = new Truck(5,"小货车",1000,10); veh[5] = new Truck(6,"大货车",2500,20); } void show(){ for(int i=0,j=veh.length; i<j; ++i){ System.out.println("------车辆情况-------"); getVeh()[i].show(); } } void exit(){ System.out.println("谢谢使用!再见!"); } void summary(int n){ Scanner input = new Scanner(System.in); int day; int sum; char yn; System.out.print("请输入你要租的天数:"); day = input.nextInt(); sum = day * veh[n].getDailyCost(); System.out.print("本次租车信息为:"); veh[n].show(); System.out.println("本次租车费用为:" + sum); System.out.print("请确认:(Y/N)"); yn = input.next().charAt(0); if(yn == 'y' || yn == 'Y'){ exit(); start(); } else{ select(); } } void select(){ show(); Scanner input = new Scanner(System.in); System.out.print("请输入你要选择的车辆序号:"); selectId = input.nextInt(); if(selectId == 0){ exit(); return; } for(int i=0,j=veh.length; i<j; ++i){ if(veh[i].getId() == selectId){ summary(i); break; } } System.out.println("输入有误,请重新选择,或者输入0退出"); select(); } void start(){ System.out.print("是否要租车? Y/N"); Scanner input = new Scanner(System.in); char yn = input.nextLine().charAt(0); if(yn == 'y' || yn == 'Y'){ select(); } else{ exit(); } } } //Main.java package Vehicle; public class Main { public static void main(String[] args) { Interaction inter = new Interaction(); inter.start(); } }
public class Bus extends Vehicle 看了半天,就是没发现Vehicle类
Java入门第二季 升级版
530652 学习 · 6091 问题
相似问题