第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

嗒嗒租車系統(tǒng)

標(biāo)簽:
Java

很粗糙的成品,很多细节都没有处理,懒得弄了。正确操作的前提没什么问题,少了一些输入不合理信息时的报错提示。强行使用了接口,弄得有点晕哈哈。


父类抽象类:

package dada;

public abstract class Car {
    private int id;
    private String name;
    private int price;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getPrice() {
        return price;
    }
    public void setPrice(int price) {
        this.price = price;
    }

}

两个接口:

package dada;

public interface ICapacity {
    void setCapacity(int cap);
    int getCapacity();
}
package dada;

public interface ICargoVolume {
    void setCargoVolume(int vol);
    int getCargoVolume();

}

分别三个子类:

package dada;

public class PassengerCar extends Car implements ICapacity {
    private int cap;

    public PassengerCar(int id,String name,int price,int cap){
        this.setId(id);
        this.setName(name);
        this.setPrice(price);
        this.setCapacity(cap);
        //客车类的属性
    }

    @Override
    public void setCapacity(int cap) {
        // TODO Auto-generated method stub
        this.cap=cap;
    }

    @Override
    public int getCapacity() {
        // TODO Auto-generated method stub
        return cap;
    }

}
package dada;

public class Pickup extends Car implements ICapacity,ICargoVolume {
    private int cap;
    private int vol;
    public Pickup(int id,String name,int price,int cap,int vol){
        this.setId(id);
        this.setName(name);
        this.setPrice(price);
        this.cap=cap;
        this.vol=vol;
        //皮卡类的属性
    }
    public int getCapacity() {
        return cap;
    }
    public void setCapacity(int cap) {
        this.cap = cap;
    }
    public int getCargoVolume() {
        return vol;
    }
    public void setCargoVolume(int vol) {
        this.vol = vol;
    }

}
package dada;

public class Truck extends Car implements ICargoVolume {
    private int vol;//载货量
    public Truck(int id,String name,int price,int vol){
        this.setId(id);
        this.setName(name);
        this.setPrice(price);
        this.vol=vol;
    }
    public int getCargoVolume() {
        return vol;
    }
    public void setCargoVolume(int vol) {
        this.vol = vol;
    }

}

运行:

package dada;
import java.util.Scanner;
public class Test {
    public static final Car[] cars={
            new PassengerCar(1,"奥迪A4",500,4),
            new PassengerCar(2,"马自达6",400,4),
            new Pickup(3,"皮卡雪6",450,4,2),
            new PassengerCar(4,"金龙",800,20),
            new Truck(5,"松花江",400,4),
            new Truck(6,"依维柯",1000,20)
    };

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("欢迎使用dada租车系统!"+"\n"+"您是否要租车:1.是"+"\t"+"0.退出");
        Scanner s = new Scanner(System.in);
        int input = s.nextInt();
        if(input ==1){
            System.out.println("可供租用的车辆及其价目表:");
            System.out.println("序号"+"\t"+"车型"+"\t"+"租金"+"\t"+"容量");
            for(Car car:cars){
                if(car.getClass().equals(PassengerCar.class)){
                    //判断该车是否是客车的实例
                    //使用getCapacity的时候需要将car强制转换成PassengerCar类型!
                    System.out.println(car.getId()+"\t"+car.getName()+"\t"+car.getPrice()+"/天"+"\t"+((PassengerCar)car).getCapacity()+"人");
                }else if(car.getClass().equals(Truck.class)){
                    System.out.println(car.getId()+"\t"+car.getName()+"\t"+car.getPrice()+"/天"+"\t"+((Truck)car).getCargoVolume()+"吨");
                }else{
                    System.out.println(car.getId()+"\t"+car.getName()+"\t"+car.getPrice()+"/天"+"\t"+((Pickup)car).getCapacity()+"人"+((Pickup)car).getCargoVolume()+"吨");
                }
            }
        }else{
            System.out.println("感谢使用dada租车系统!");
        }
        System.out.println("请输入您要租车的数量:");
        int count = s.nextInt();
        Car rent[] = new Car[count];
        for(int i=0; i<count;i++){
            System.out.println("请输入第"+(i+1)+"辆车的序号");
            int num = s.nextInt();
            rent[i]=cars[num-1];
        }
        System.out.println("请输入租车的天数:");
        int days  = s.nextInt();
        int sum = 0;
        for(Car car: rent){
            System.out.println(car.getName());
        }
        System.out.println("以下是您本次的租车信息及账单:");
        System.out.println("您本次共租用"+count+"辆车:");
        for(int i= 0;i<rent.length;i++){
            if(rent[i]!=null){
                System.out.println(rent[i].getName());
            }else{

            }
            sum += rent[i].getPrice()*days;
        }
        System.out.println("您本次需支付:"+sum+"元");
        s.close();
    }
}

运行结果:
图片描述

點(diǎn)擊查看更多內(nèi)容
8人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消