实现汽车租赁系统的计价功能

package rent1;
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 rent1;
import com.rent.MotoVehicle;
 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 rent1;
/**
 *  MotoVehicle:机动车抽象类
 * @author 水瓶
 *
 */
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 rent1;
import java.util.Scanner;
public class Test {
 /**
  * @author 水瓶
  * @param args
  */
  
  public static void main(String[] args){
   Scanner input = new Scanner(System.in);
   int days = 0;    //租赁的天数
   int motoType ;   //汽车大类型
   String brand ;   //汽车品牌
   int seat;        //座位数
   String no = null;       //牌照
   MotoVehicle[] moto = new MotoVehicle[10];
   
   System.out.println("欢迎来到汽车租赁公司!"); 
   
   System.out.println("请输入要租赁的天数:");
   days = input.nextInt();
   
  
    System.out.println("请输入要租赁的汽车类型(1.轿车 2.客车):");
    motoType = input.nextInt();
   
    int random = (int)(Math.random()*(99999-10000)+10000);
    switch(motoType){
    case 1: 
     no = "蒙D" + random;   //车辆牌照
     
     System.out.println("请输入要租赁的汽车品牌(1.宝马  2.丰田):");
     if(input.nextInt() == 1){
      brand = "玛莎拉蒂";
     }else{
      brand = "广汽"; 
      break;
     }
    case 2:
     no = "蒙D" + random; 
     
     System.out.println("请输入要租赁的汽车品牌(1.黄海  2.金龙):");
     //根据选择得到汽车品牌
     if(input.nextInt() ==1){
      brand = "黄海";
     }else{
      brand = "金龙";
     }
     System.out.println("请输入客车的座位数:");
     seat = input.nextInt();   //汽车座位数     
     for(int i = 0 ; i < moto.length ;i ++){
      if(moto[i] == null){
       moto[i] = new Bus(no,brand,seat);   //实例化一个汽车对象
       break;
      }
     }
    }
   System.out.println("租赁天数:"+days+"天\n租赁资金是:"+random+"元\n汽车牌照:"+no);
  }
}
 


  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值