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

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

Java入門(mén)第二季租車(chē)系統(tǒng)

標(biāo)簽:
Java

测试类

package dadazuche;

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double totalPrice=0; //总价格
        int totalPerson = 0;//总人数;
        double totlaGoods=0;//总货重量

        System.out.println("*****欢迎使用DADA租车系统*****"); 
        System.out.println("您是否需要租车:1是  0否");

        Scanner input =new Scanner(System.in);
        int choice = input.nextInt();
        if(choice==1){
            System.out.println("*****您可租车的类型及价目表如下所示*****");
            Car[] car ={new XiaoCar("奥迪",500,4),
                        new PickUp("皮卡",300,2,2.0)};
            System.out.println("序号\t汽车名称\t租金\t\t人数\t载重T");
            for (int i=0;i<car.length;i++) {
                System.out.print(i+1 +"\t" + car[i].carName+"\t"+car[i].carPrice+"元/天\t");
                if(car[i] instanceof XiaoCar){
                    System.out.println("载人:"+car[i].getManNum());
                }else if(car[i] instanceof PickUp){
                    System.out.println("载人:"+car[i].getManNum()+"\t载重:"+car[i].getLoad());
                }
            }
            System.out.println("=============================");
            System.out.println("请输入你要租车的数量(最多3辆):");

            int rentNum = input.nextInt();
            int[]rentArray = new int[rentNum];//输入的数量就是数组的长度
            for(int i=1;i<=rentNum; i++)
            {
                System.out.println("请输入第"+i+"的序号");
                rentArray[i-1]=input.nextInt()-1;
            }
            System.out.println("请输入租车的天数:");
            int rentDay =input.nextInt();
            System.out.println("你的账单:");
            System.out.println("===========");
            int CarNum=0; //车的数量 
                for (int i = 0; i < rentArray.length; i++) {
                    if(car[rentArray[i]] instanceof XiaoCar ||car[rentArray[i]] instanceof PickUp){

                        if(car[rentArray[i]]  instanceof XiaoCar){
                            System.out.println(car[rentArray[i]].getCarName()+"车");
                        }else{
                            System.out.println(car[rentArray[i]].getCarName()+"车");
                        }
                        CarNum++;  
                        //总人数
                        totalPerson +=car[rentArray[i]].getManNum();
                        //总价格
                        totalPrice +=car[rentArray[i]].getCarPrice() * rentDay;
                        //总重量
                        totlaGoods +=car[rentArray[i]].getLoad();
                    }
                }
            System.out.println("总共租车"+CarNum+"辆,"+"租"+rentDay+"天,"+"可以载"+totalPerson+"人,"+"总载重"+totlaGoods+"T,"+"租金总共"+totalPrice+"元.");
            }else{
                System.out.println("退出系统,感谢你的使用!");

            }
        input.close();  
    }   
}
父类
package dadazuche;

public class Car {
    String carName; //汽车名称

    double carPrice;//汽车租金
    int    manNum;//载人数
    double    load;     //汽车载重
    /*载人*/
    public Car(String carName, double carPrice, int manNum) {
        super();
        this.carName = carName;
        this.carPrice = carPrice;
        this.manNum = manNum;
    }
    //载人载货
    public Car(String carName, double carPrice, int manNum, double load) {
        super();
        this.carName = carName;
        this.carPrice = carPrice;
        this.manNum = manNum;
        this.load = load;
    }

    public String getCarName() {
        return carName;
    }
    public void setCarName(String carName) {
        this.carName = carName;
    }
    public double getCarPrice() {
        return carPrice;
    }
    public void setCarPrice(double carPrice) {
        this.carPrice = carPrice;
    }
    public int getManNum() {
        return manNum;
    }
    public void setManNum(int manNum) {
        this.manNum = manNum;
    }
    public double getLoad() {
        return load;
    }
    public void setLoad(double load) {
        this.load = load;
    }

}

两个子类都一样

package dadazuche;

public class PickUp extends Car {

    public PickUp(String carName, double carPrice, int manNum, double load) {
        super(carName, carPrice, manNum, load);
        // TODO Auto-generated constructor stub
    }
}
package dadazuche;

public class XiaoCar extends Car {

    public XiaoCar(String carName, double carPrice, int manNum) {
        super(carName, carPrice, manNum);
        // TODO Auto-generated constructor stub
    }

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

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

評(píng)論

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

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(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
提交
取消