ITPub博客

首页 > IT职业 > IT图书 > 哒哒租车-贰零壹柒零叁月壹拾肆日

哒哒租车-贰零壹柒零叁月壹拾肆日

IT图书 作者:corespeed 时间:2021-09-09 09:00:01 0 删除 编辑

demo

package dada;

import java.util.Scanner;

public class Demo {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("欢迎使用哒哒租车系统");
        System.out.println("您是否要租车:1是 0否");
        int s = sc.nextInt();
        Car[] cars = {new Keche( 500, "奥迪A4",4),
                new Keche( 400, "马自达6",5),
                new Keche( 450, "金杯面包",21),
                new Huoche( 800, "松花江",5),
                new Huoche( 1100, "东风",20),
                new Kehuoche( 500, "皮卡",3,8),};
        if(s == 0){
            System.out.println("谢谢使用");
        }else{
            System.out.println("价目表如下");
            System.out.println("序号            车型                       价格                       容量");
            for(int i = 1; i 

car

package dada;

public class Car {

    private int price;
    private String name;
    private int passengerLoad;  //载人量
    private double goodsLoad;   // 

    public int getPrice() {
        return price;
    }
    public void setPrice(int price) {
        this.price = price;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getPassengerLoad() {
        return passengerLoad;
    }
    public void setPassergerLoad(int passengerLoad) {
        this.passengerLoad = passengerLoad;
    }
    public double getGoodsLoad() {
        return goodsLoad;
    }
    public void setGoodsLoad(double goodsLoad) {
        this.goodsLoad = goodsLoad;
    }
}

客车

package dada;

public class Keche extends Car {

    public Keche(int price, String name, int passengerLoad) {
        super();
        this.setPrice(price);
        this.setName(name);
        this.setPassergerLoad(passengerLoad);
    }

    public String toString(){
        return this.getName() + "          " + this.getPrice() + "元/天               " + "载客" + this.getPassengerLoad() + "人";
    }

}

货车

package dada;

public class Huoche extends Car {

    public Huoche(int price, String name , double goodsLoad) {
        super();
        this.setPrice(price);
        this.setName(name);
        this.setGoodsLoad(goodsLoad);
    }

    public String toString(){
        return this.getName() + "                  " + this.getPrice() + "元/天             " + "载货" +this.getGoodsLoad() + "吨";
    }

}

皮卡

package dada;

public class Kehuoche extends Car {

    public Kehuoche(int price, String name, int passengerLoad, double goodsLoad) {
        super();
        this.setPrice(price);
        this.setName(name);
        this.setPassergerLoad(passengerLoad);
        this.setGoodsLoad(goodsLoad);
    }

    public String toString() {
        return this.getName() + "                  " + this.getPrice() + "元/天               " + "载客" + this.getPassengerLoad() + "人/载货" + this.getGoodsLoad() + "吨";
    }

}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4440/viewspace-2798477/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-09

  • 博文量
    90
  • 访问量
    1012