首页 > IT职业 > IT生活 > Java测试-----达达租车系统
测试类
package coom.car_rental.java;
import java.util.Scanner;
/*
* 这是测试主类
*/
public class CarRental implements cars{
public static void main(String[] args) {
// TODO 自动生成的方法存根
System.out.println("欢迎使用达达租车系统!");
System.out.println("请问您是否需要租车? 0-否 1-是 ");
Scanner sc = new Scanner(System.in);
int op1 = sc.nextInt();
switch (op1) {
case 0:
System.out.println("欢迎您使用达达租车系统!" + "n" +
"期待您的再次使用!" + "n" + "再见!");
System.exit(0);
case 1:
System.out.println("您可租用车的数量及价格表");
System.out.println("序号"+ "t车名" + "t车的载客量(人)" + "t车的载货量(吨)"
+ "t车的价格(天/元)");
//循环输出车的信息
for(int i = 0;i Car类
package coom.car_rental.java;
public abstract class Car {
public String name;//车的名字
public int carNumber;//租车数量
public int busload;//载客量
public int burden;//载货量
public double dailyRent;//日租金
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCarNumber() {
return carNumber;
}
public void setCarNumber(int carNumber) {
this.carNumber = carNumber;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public int getBurden() {
return burden;
}
public void setBurden(int burden2) {
this.burden = burden2;
}
public double getDailyRent() {
return dailyRent;
}
public void setDailyRent(double dailyRent) {
this.dailyRent = dailyRent;
}
}
车库类
package coom.car_rental.java;
public interface cars {
Car[] cars = {
new PassengerCar("奥迪A4", 4, 500),
new PassengerCar("马自达6", 4, 400),
new PickupTruck("皮卡雪6", 4, 2, 450),
new PassengerCar("金龙", 20, 800),
new Truck("松花江", 4, 400),
new Truck("依维柯", 20, 1000)};
}
卡车类
package coom.car_rental.java;
/*
* 这是货车类,载货的
*/
public class Truck extends Car {
public Truck(String name, int burden, double dailyRent) {
// TODO 自动生成的构造函数存根
this.setName(name);
this.setBurden(burden);
this.setDailyRent(dailyRent);
}
public String toString() {
return this.getName() + "t" +this.getBurden() + "tt" + this.getDailyRent();
}
}
客车类
package coom.car_rental.java;
/*
* 这是客车类,载人的
*/
public class PassengerCar extends Car {
public PassengerCar(String name, int busload,double dailyRent) {
// TODO 自动生成的构造函数存根
this.setName(name);
this.setBusload(busload);
this.setDailyRent(dailyRent);
}
public String toString() {
return this.getName() +"t" + this.getBusload() + "tttt" + this.getDailyRent();
}
}
皮卡类
package coom.car_rental.java;
/*
* 这是皮卡车类,既可以载人也可以载货
*/
public class PickupTruck extends Car {
public PickupTruck(String name, int busload, int burden, double dailyRent) {
// TODO 自动生成的构造函数存根
this.setName(name);
this.setBusload(busload);
this.setBurden(burden);
this.setDailyRent(dailyRent);
}
public String toString () {
return this.getName() + "t" + this.getBusload() + "tt"
+ this.getBurden() + "tt" + this.getDailyRent();
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1696/viewspace-2808144/ ,如需转载,请注明出处,否则将追究法律责任。