zoukankan      html  css  js  c++  java
  • 租赁车辆(多车)程序

     1 package carsRental;
     2 /**
     3  * 抽象类,机动车类
     4  * @author Administrator
     5  *
     6  */
     7 public abstract class MotoVehicle {
     8     //不用private,protected直接调用
     9     protected String no;
    10     protected String brand;
    11     protected String color;
    12     protected int mileage;
    13     
    14     /*protected MotoVehicle(){}
    15     protected MotoVehicle(String No,String Brand,String Color,int Mileage){
    16         this.No=No;
    17         this.Brand=Brand;
    18         this.Color=Color;
    19         this.Mileage=Mileage;*/
    20     public MotoVehicle(){}
    21     public MotoVehicle(String no, String brand, String color, int mileage) {
    22         super();
    23         this.no = no;
    24         this.brand = brand;
    25         this.color = color;
    26         this.mileage = mileage;
    27     }
    28     
    29     public String getNo() {
    30         return no;
    31     }
    32     public void setNo(String no) {
    33         this.no = no;
    34     }
    35     public String getBrand() {
    36         return brand;
    37     }
    38     public void setBrand(String brand) {
    39         this.brand = brand;
    40     }
    41     public String getColor() {
    42         return color;
    43     }
    44     public void setColor(String color) {
    45         this.color = color;
    46     }
    47     public int getMileage() {
    48         return mileage;
    49     }
    50     public void setMileage(int mileage) {
    51         this.mileage = mileage;
    52     }
    53     /**
    54      * 计算租金
    55      * @param days
    56      * @return
    57      */
    58     public abstract double calcRent(int days);
    59 //    public abstract int CalcRent(int days);
    60     
    61 }
     1 package carsRental;
     2 /**
     3  * 轿车类,继承机动车类
     4  * @author Administrator
     5  *
     6  */
     7 public final class Car extends MotoVehicle {
     8     private String type;
     9     /*@Override
    10     public final double CalcRent(int days) {
    11         if(type.equals("别克商务舱GL8")){
    12             int count=days*600;
    13             System.out.println("别克商务舱GL8的租赁价为"+count);
    14         }else if(type.equals("宝马550i")){
    15             int count=days*500;
    16             System.out.println("车牌号为"+super.getNo()+"宝马550i的租赁价为"+count);
    17         }else if(type.equals("别克林荫大道")){
    18             int count=days*300;
    19             System.out.println("别克林荫大道的租赁价为"+count);
    20         }
    21         return days;
    22     }*/
    23     public Car(){}
    24     public Car(String no, /*String brand, String color, int mileage,*/String type){
    25 //        super(no,brand,color,mileage);
    26         this.no=no;
    27         this.type=type;
    28     }
    29     public String getType() {
    30         return type;
    31     }
    32     public void setType(String type) {
    33         this.type = type;
    34     }
    35     public double calcRent(int days){
    36         double total=0;
    37         if("别克商务舱GL8".equals(type)){
    38             total=600*days;
    39             System.out.println("车牌号为"+super.getNo()+"别克商务舱GL8的租赁价为"+total);
    40         }else if("宝马550i".equals(type)){
    41             total=500*days;
    42             System.out.println("车牌号为"+super.getNo()+"宝马550i的租赁价为"+total);
    43         }else if("别克林荫大道".equals(type)){
    44             total=300*days;
    45             System.out.println("车牌号为"+super.getNo()+"别克林荫大道的租赁价为"+total);
    46         }
    47         return total;
    48     }
    49 }
     1 package carsRental;
     2 /**
     3  * 客车类,继承机动车类
     4  * @author Administrator
     5  *
     6  */
     7 public final class Bus extends MotoVehicle {
     8     private int seatCount;
     9     /*@Override
    10     public final double CalcRent(int days) {
    11         if(seatCount<=16){
    12             int count=days*800;
    13             System.out.println("客车的租赁价格为"+count);
    14         }else if(seatCount>16){
    15             int count=days*1500;
    16             System.out.println("客车的租赁价格为"+count);
    17         }
    18         return days;
    19     }*/
    20     public Bus(){}
    21     public Bus(String no,int seatcount){
    22         this.no=no;
    23         this.seatCount=seatcount;
    24     }
    25     public int getSeatCount() {
    26         return seatCount;
    27     }
    28     public void setSeatCount(int seatCount) {
    29         this.seatCount = seatCount;
    30     }
    31     @Override
    32     public double calcRent(int days) {
    33         if(seatCount<=16){
    34             double count=800*days;
    35             System.out.println("车牌号为"+super.getNo()+"客车的租赁价为"+count);
    36             return 800*days;
    37             
    38         }else{
    39             double count=800*days;
    40             System.out.println("车牌号为"+super.getNo()+"客车的租赁价为"+count);
    41             return 1500*days;
    42             
    43         }
    44     }
    45 }
     1 package carsRental;
     2 
     3 import java.util.Scanner;
     4 
     5 public class TestMotoVehicle {
     6     public static void main(String[]args){
     7 //        Car car=new Car("京NY28588","宝马550i"/*, null, 0, null*/);
     8 //        car.CalcRent(12);
     9 //        Car car=new Car();
    10 //        Bus bus=new Bus();
    11         //利用机动车作为数组类型
    12         MotoVehicle[]motos=new MotoVehicle[4];
    13         motos[0]=new Car("京NY28588","宝马550i");
    14         motos[1]=new Car("京NNN328","宝马550i");
    15         motos[2]=new Car("京NY28588","别克林荫大道");
    16         motos[3]=new Bus("沪AK47633",34);
    17         //计算租车租金
    18 //        public int CalcTotalRent(MotoVehicle[]motos){
    19             double sumPrice=0;
    20             for(int i=0;i<motos.length;i++){
    21             MotoVehicle moto=motos[i];
    22             sumPrice+=moto.calcRent(1);
    23 //            totalRent=+motos[i].CalcRent(1);
    24         }
    25             System.out.println("总租金为"+sumPrice);
    26 //            return totalRent;
    27     }
    28 }    
  • 相关阅读:
    [视频监控]用状态机图展示Layout切换关系
    初次打开mysql5.6后
    eclipse 项目乱码
    java servlet 中遇到的编码问题
    解决HttpServletResponse输出的中文乱码问题
    The first day of my Blog
    最大子段和
    LOI 54 成立一周年纪(zuo)念(si)
    水题 逆序对 NOIP 2013 火柴排队
    搜索 由浅入深 之一 水题
  • 原文地址:https://www.cnblogs.com/SUN99bk/p/10476553.html
Copyright © 2011-2022 走看看