首页 > IT职业 > IT图书 > 20170703答答用车系统
创建Car类
public class Car {
public String carName; //车名
public int ID, personLoad; //序号、载客量
public double carRental, meterLoad; //租金、载货量
@Override
public String toString() {
return "ID:" + ID + ", 名称:" + carName
+ ", 载客量:" + personLoad + ", 载货量:"
+ meterLoad + ", 租金:" + carRental;
} }
创建Bus类,继承Car类
public class Bus extends Car {
public Bus() {
super();
// TODO Auto-generated constructor stub
}
public Bus(int ID, String carName, int personLoad, double meterLoad, double carRental){
this.ID = ID;
this.carName = carName;
this.personLoad = personLoad;
this.meterLoad = meterLoad;
this.carRental = carRental;
} }
创建皮卡类,继承Car类
public class PickUp extends Car {
public PickUp() {
super();
// TODO Auto-generated constructor stub
}
public PickUp(int ID, String carName, int personLoad, double meterLoad, double carRental){
this.ID = ID;
this.carName = carName;
this.personLoad = personLoad;
this.meterLoad = meterLoad;
this.carRental = carRental;
} }
创建卡车类,继承Car类
public class Truck extends Car {
public Truck() {
super();
// TODO Auto-generated constructor stub
}
public Truck(int ID, String carName, int personLoad, double meterLoad, double carRental){
this.ID = ID;
this.carName = carName;
this.personLoad = personLoad;
this.meterLoad = meterLoad;
this.carRental = carRental;
} }
创建展示类,答答用车系统界面
import java.util.Scanner;
public class Show {
public static void main (String[] args){
System.out.println("欢迎使用答答租车系统");
System.out.println("您是否要租车呢?1是;0否");
Scanner sn = new Scanner(System.in);
int isGet = sn.nextInt(); //判断是否需要租车
if (isGet == 1){
//显示车的信息
System.out.println("在库车的信息如下:序号、名称、载客数、载货量、租金"); //显示车的信息
Car[] car = new Car[]{new Bus(1, "奥迪A4", 500, 0, 4),
new Bus(2, "马自达6", 400, 0, 4),
new PickUp(3, "皮卡雪", 450, 4, 2),
new Bus(4, "金龙", 800, 0, 20),
new Truck(5, "松花江", 0, 400, 4),
new Truck(6, "依维柯", 0, 1000, 20)};
for(int i = 0; i 0){
//创建数组,用于存储员工输入的车序号
int[] CarNum = new int[useCarNum];
//将序号写入到数组中中
for (int i = 1; i 0){
double Totalmoney = 0;
//打印用车信息
System.out.println("您使用的车如下:");
for(int i = 0; i }
显示结果
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3598/viewspace-2799033/ ,如需转载,请注明出处,否则将追究法律责任。