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

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

Java入門第二季租車系統(tǒng)

標(biāo)簽:
Java

定义父类Auto

package com.Imooc;

public abstract class Auto {
    private  String model;//汽车型号
    private  int rent;//汽车租金
    private  int capacity;//汽车载客量
    private  int cargo;//汽车载货量

    //以下为各个变量的设置与获取方法

    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public double getRent() {
        return rent;
    }
    public void setRent(int rent) {
        this.rent = rent;
    }
    public int getCapacity() {
        return capacity;
    }
    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }
    public int getCargo() {
        return cargo;
    }
    public void setCargo(int cargo) {
        this.cargo = cargo;
    }

}

定义子类Bus

package com.Imooc;
public class Bus extends Auto{
    //载客用车初始化
        public Bus(String newmodel, int newrent, int capacity) {
            // TODO Auto-generated method stub
            this.setModel(newmodel);
            this.setRent(newrent);
            this.setCapacity(capacity);
        }
}

定义子类Truck

package com.Imooc;

public class Truck extends Auto {

    //卡车的初始化
    public  Truck(String newmodel,int newrent,int newcargo){
        this.setModel(newmodel);
        this.setRent(newrent);
        this.setCargo(newcargo);
    }

}

定义子类Pickup

package com.Imooc;

public class Pickup extends Auto {

    //皮卡车的初始化
    public  Pickup(String newmodel,int newrent, int newcapacity,int cargo){
        this.setModel(newmodel);
        this.setRent(newrent);
        this.setCapacity(newcapacity);
        this.setCargo(newcapacity);
    }
}

测试函数

package com.Imooc;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Auto[] carsForRent = {new Bus("五菱",100,7),new Pickup("福特",150,2,2),new Truck("东风", 150, 5)};
        System.out.println("欢迎来到租车系统,请问您要租车吗?");
        System.out.println("租车请输入1,退出请输入0");
        Scanner scan = new Scanner(System.in);
        String input = scan.next();
        if(input.equals("1")){//
            System.out.println("您可租车的类型及其价目表:");
            System.out.println("序号\t汽车名称\t租金\t载客量\t载货量");
            for(Auto currentCar:carsForRent){//遍历已存数组内的数据
                if(currentCar instanceof Bus){
                    System.out.println(""+1+"\t"+currentCar.getModel()+"\t"+currentCar.getRent()+"\t"+currentCar.getCapacity());
                }
                else if(currentCar instanceof Pickup){
                    System.out.println(""+2+"\t"+currentCar.getModel()+"\t"+currentCar.getRent()+"\t"+currentCar.getCapacity()+"\t"+currentCar.getCargo());
                }
                else{
                    System.out.println(""+3+"\t"+currentCar.getModel()+"\t"+currentCar.getRent()+"\t\t"+currentCar.getCargo());
                }
            }
        }
        else{
            System.out.println("谢谢光临租车系统,再见!");
        }
        System.out.println("请输入序号选择您所需要的车");
        String input2 = scan.next();
        switch (input2){
        case "1":System.out.println("您选择了"+carsForRent[0].getModel()+",租金为每日"+carsForRent[0].getRent()+"元,"+"载客量为"+carsForRent[0].getCapacity()+"人");
        break;
        case "2":System.out.println("您选择了"+carsForRent[1].getModel()+",租金为每日"+carsForRent[1].getRent()+"元,"+"载客量为"+carsForRent[1].getCapacity()+"人,载货量为"+carsForRent[1].getCargo()+"吨。");
        break;
        case "3":System.out.println("您选择了"+carsForRent[2].getModel()+",租金为每日"+carsForRent[2].getRent()+"元,"+"载货量为"+carsForRent[1].getCargo()+"吨");
        }
        System.out.println("谢谢惠顾");
    }
}

主函数部分参考了Java入门第二季最后一个视频里的代码

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

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

評(píng)論

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

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

100積分直接送

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

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

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

購(gòu)課補(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
提交
取消