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

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

答答租車系統(tǒng)簡(jiǎn)易版(50行代碼)

標(biāo)簽:
Java

此答答租车系统简易版为JAVA学习第二季最终练习。简易版中没有区分载人、载重这两种方式,故还没有使用接口。。
程序分为3个类。父类Car,子类MixCar,主运行类Manage。将方法定义在对象中,主程序直接执行即可。
父类Car (构造方法)

public class Car {
     String Type;
     int PerSit;
     double price;
     int goods;

    public Car(String type,int persit,double price,int goods){
        this.Type=type;
        this.PerSit=persit;
        this.price=price;
        this.goods=goods;

}
}

子类Mixcar
定义了输出方法。列印

public class Mixcar extends Car{

    public Mixcar(String type, int persit, double price, int goods) {
        super(type, persit, price, goods);
        // TODO Auto-generated constructor stub
        this.Type=type;
        this.PerSit=persit;
        this.price=price;
        this.goods=goods;

    }
              public void mixShow(){
                  System.out.println(this.Type+"\t"+this.PerSit+"\t"+
              this.price+"元/天"+"\t"+this.goods+"吨");
              }

}

执行类Manage


import java.util.*;
public class Manage{
    public static void main(String[] args) {
        //创建数组并实例化赋值
        Mixcar arrmix[]={new Mixcar("皮卡", 3, 450,5 ),new Mixcar("依维柯",10,550,10),new Mixcar("奥迪A4",5,450,0),
                new Mixcar("奔驰C200",5,500,0),new Mixcar("东风",3,550,55)};
        //创建临时存放Mixcar对象实例,用于保存用户选择的车型
        Mixcar mixx=new Mixcar("null",0,0,0);
        //用于保存用户选择的时间
        int carDate=0;
        System.out.println("欢迎使用租车系统\t 您是否要租车:1 是  0否");
        //接收用户输入的数字
        Scanner sc=new Scanner(System.in);
        int choose=sc.nextInt();
        if(choose==0){
            System.out.println("期待您的下次光临");
            System.exit(choose);
        }else if(choose==1){
            System.out.println("我们现有的车型和价格是\t");
        }else{
            System.out.println("输入错误,请重新输入");
            main(args);
            //此处需要一个方法,使得输入错误的情况可以返回从新输入
        }System.out.println("车型\t"+"车载人数\t"+"价格\t"+"载重");
        for(int i=0;i<arrmix.length;i++){
            arrmix[i].mixShow();
        }
        System.out.println("--------我是邪恶的分割线---------");
        System.out.println("输入选择的车型");
        int carType=new Scanner(System.in).nextInt();
        switch(carType){
        case 1: mixx=arrmix[0];
                break;
        case 2: mixx=arrmix[1];
                break;
        case 3: mixx=arrmix[2];
                break;
        case 4: mixx=arrmix[3];
                break;
        case 5: mixx=arrmix[4];
                break;
        }
        System.out.println("输入租用的日期");
         carDate=new Scanner(System.in).nextInt();
        System.out.println("您选用的车型为"+mixx.Type+"\t"+"日费用为"+mixx.price+"\t"+"总费用为"+(mixx.price*carDate));

    }
}
點(diǎn)擊查看更多內(nèi)容
10人點(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
提交
取消