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

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

達(dá)達(dá)租車系統(tǒng)(借鑒了他人的代碼)

標(biāo)簽:
Java
package java入门第二季达达租车系统;

public class Car {
    public String name;//汽车名称
    public int price;//汽车租金
    public int ren;//载人数
    public int huo;//载货数

    public Car(String name, int price) {
        super();
        this.name = name;
        this.price = price;
    }
    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;
    }
    public int getRen() {
        return ren;
    }
    public void setRen(int ren) {
        this.ren = ren;
    }
    public int getHuo() {
        return huo;
    }
    public void setHuo(int huo) {
        this.huo = huo;
    }

}

载人的车

package java入门第二季达达租车系统;

public class PersonCar extends Car{

    public PersonCar(String name, int price,int ren) {
        super(name, price);
        this.ren=ren;
    }

    public String toString(){
        return this.name+"\t"+this.price+"元/天"+"\t"+"载人:"+this.ren+"人";
    }

}

载货的车

package java入门第二季达达租车系统;

public class HuoCar extends Car{

    public HuoCar(String name, int price,int huo) {
        super(name, price);
        this.huo=huo;
    }

    public String toString(){
        return this.name+"\t"+this.price+"元/天"+"\t"+"载货:"+this.huo+"吨";
    }

}

皮卡

package java入门第二季达达租车系统;

public class PkCar extends Car{

    public PkCar(String name, int price,int ren,int huo) {
        super(name, price);
        this.ren=ren;
        this.huo=huo;
    } 

    public String toString(){
        return this.name+"\t"+this.price+"元/天"+"\t"+"载人:"+this.ren+"人"+" 载货:"+this.huo+"吨";
    }

}

主函数


package java入门第二季达达租车系统;

import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
    while(true) {//使循环
        System.out.println("欢迎使用达达租车系统:");
        System.out.println("您是否要租车: 1是  0否");
        int s = sc.nextInt();

        if(s==1){
            System.out.println("您可租车的类型及其价目表:");
            System.out.println("序号                汽车名称        租金              容量");
//          Car c1 = new PersonCar("奥迪A4",500,4);
//          Car c2 = new PersonCar("马自达6",400,4);
//          Car c3 = new PkCar("皮卡雪6",450,4,2);
//          Car c4 = new PersonCar("金龙",800,20);
//          Car c5 = new HuoCar("松花江",400,4);
//          Car c6 = new HuoCar("依维柯",1000,20);
            //定义Car数组,并实例化对象
            Car[] cars ={ new PersonCar("奥迪A4",500,4),
                          new PersonCar("马自达6",400,4),
                          new PkCar("皮卡雪6",450,4,2),
                          new PersonCar("金龙",800,20),
                          new HuoCar("松花江",400,4),
                          new HuoCar("依维柯",1000,20)};
            for(int i=0;i<cars.length;i++){
                System.out.println((i+1)+"\t"+cars[i]);
            }

            System.out.println("请输入您要租车的数量:");
            int num = sc.nextInt();

            //定义相关变量来存放数据
            Car[] carList = new Car[num];//创建一个新的数组来接收选择出来的车;数量是num
            int rens = 0;//用来记录人数
            int huos = 0;//用来记录货物数量
            int prices = 0;//用来记录总价格
            //遍历循环输出要租车的序号
            for(int i=0;i<num;i++){
                System.out.println("请输入第"+(i+1)+"辆车的序号");
                int xun= sc.nextInt();
                carList[i]  = cars[xun-1];//将车的序列赋值给数组carList
                prices += carList[i].getPrice(); //
            }
            //输出租车天数
            System.out.println("请输入租车天数:");
            int tian = sc.nextInt();
            prices = prices*tian;
            System.out.println("---------------");

            System.out.println("您的账单:");
            System.out.println("***可载人的车有:");
            //遍历循环查询可载人的车
            for(int i=0;i<num;i++){
                //如果车是PersonCar 和PkCar都可以载人
                if(carList[i] instanceof PersonCar || carList[i] instanceof PkCar){
                    rens = rens+carList[i].getRen();
                    System.out.print(carList[i].getName()+"\t");
                }   
            }
            System.out.println("共载人:"+rens+"人");
            System.out.println("***可载货的车有:");
            //遍历循环查询可载货的车
            for(int i=0;i<num;i++){
                if(carList[i] instanceof HuoCar || carList[i] instanceof PkCar){
                    huos = huos+carList[i].getHuo();
                    System.out.print(carList[i].getName()+"\t");
                }
            }
            System.out.println("共载货:"+huos+"吨");
            System.out.println("***租车的总价格:"+prices+"元");
            return;
        }else if(s==0){
            System.out.println("欢迎下次再来");
            return;
        }else {
            System.out.println("您的输入有误");
        }
    }

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