java汽车租赁系统

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

package RentCar;

public class Bus extends MotoVehicle{

private int seatCount;

//构造方法

public Bus(){

}

public Bus(String no, String brand, int seatCount){ super(no,brand);

this.seatCount = seatCount;

}

//获取座位数

public int getSeat(){

return seatCount;

}

//计算租金

public int calRent(int days){

int rent = 0;

if(seatCount <= 16){

rent = 800 * days;

}else{

rent = 1500 * days;

}

return rent;

}

} ……………………………………………………………………………………………………………package RentCar;

public class Car extends MotoVehicle {

private String type; // 轿车的型号

//构造方法

public Car(){

}

public Car(String no, String brand, String type){

super(no,brand);

this.type = type;

}

//设置轿车的型号

public void setType(String type){

this.type = type;

}//返回轿车型号

public String getType(){

return type;

}

//实现父类抽象方法,计算租金

public int calRent(int days){

int rent = 0;

if("宝马".equals(getBrand())){

rent = days * 500;

}else if("丰田".equals(getBrand())){

if(type.equals("GL8")){

rent = days * 600;

}else{

rent = days * 300;

}

}

return rent;

}

}

……………………………………………………………………………………………………………package RentCar;

public class Customer {

private String name;

public Customer(){

}

public Customer(String name){

= name;

}

public String getName(){

return name;

}

public int calcTotalRent(MotoVehicle[] moto, int days){

int rent = 0 ;

for(int i = 0 ;i < moto.length; i++){

if(moto[i]!=null){

rent = rent + moto[i].calRent(days);

}

}

return rent;

}

}

……………………………………………………………………………………………………………package RentCar;

public abstract class MotoVehicle {

private String no; //车牌号

private String brand; //品牌

//构造方法

public MotoVehicle(){

}

public MotoVehicle(String no, String brand){

this.no = no;

this.brand = brand;

}

//返回机动车辆的牌照

public String getNo(){

return no;

}

//返回机动车辆的品牌

public String getBrand(){

return brand;

}

//计算租金的抽象方法

public abstract int calRent(int days);

}

……………………………………………………………………………………………………………package RentCar;

import java.util.Scanner;

public class Test {

public static void main(String[] args){

Scanner input = new Scanner(System.in);

int days = 0; //租赁的天数

int motoType ; //汽车大类型

String brand ; //汽车品牌

String type = null; //汽车具体类型

int seat; //座位数

String no; //拍照

String answer; //是否继续

MotoVehicle[] moto = new MotoVehicle[10];

Customer customer = new Customer("小明");

System.out.println("欢迎来到汽车租赁公司!");

System.out.print("请输入要租赁的天数:");

days = input.nextInt();

do{

System.out.print("请输入要租赁的汽车类型(1.轿车 2.客车):");

相关文档
最新文档