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

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

答答租車系統(tǒng),早上實(shí)現(xiàn)

標(biāo)簽:
Java

業務:計算價格、計算載人量、計算載貨量;
代碼實現:Calc接口、Car類、各種車型類繼承Car類
接口Calc:

package com.dadataxi;

public interface Calc {
    public double calcPrice(int days,int num);
    public int calcPersons(int num);
    public double calcGoods(int num);
}

Car類,实现接口calc;

package com.dadataxi;

public class Car implements Calc{
    public String name; //车名
    public double price;//租车价格
    public int persons;//载客量
    public double goods;//载货量
    public boolean isPerson;//是否可载人
    public boolean isGood;//是否可载货
    /**
     * @param days 租车天数
     * @param num  租车数量
     * @return double类型 某种类型车租车总价
     */
    @Override
    public double calcPrice(int days,int num) {
        // TODO Auto-generated method stub
        return price*days*num;
    }
    /**
     * @param num  租车数量
     * @return int类型 某种类型车可乘坐人数
     */
    @Override
    public int calcPersons(int num) {
        // TODO Auto-generated method stub
        return persons*num;
    }
    /**
     * @param num  租车数量
     * @return int类型 某种类型车可载货量
     */
    @Override
    public double calcGoods(int num) {
        // TODO Auto-generated method stub
        return goods*num;
    }
}

载人车辆:

package com.dadataxi;

public class PersonCar extends Car{
    //使用构造函数初始化车辆属性
    public PersonCar(String name,double price,int persons) {
        this.name = name;
        this.price = price;
        this.persons = persons;
        this.isPerson = true;
    }
    //使用toString方法输出
    public String toString() {
        return name+"\t"+price+"\\天"+"\t"+"载人:"+persons+"人";
    }
}

皮卡车型:

package com.dadataxi;

public class PiKa extends Car {
    //使用构造函数初始化车辆属性
    public PiKa(String name,double price,int persons,double goods) {
        this.name = name;
        this.price = price;
        this.persons = persons;
        this.isPerson = true;
        this.isGood = true;
        this.goods = goods;
    }
    //使用toString方法输出
    public String toString() {
        return name+"\t"+price+"\\天"+"\t"+"载人:"+persons+"人"+"载货:"+goods+"吨";
    }
}

货车类

package com.dadataxi;

public class HuoChe extends Car{
    //使用构造函数初始化车辆属性
    public HuoChe(String name,double price,double goods) {
        this.name = name;
        this.price = price;
        this.goods = goods;
        this.isGood = true;
    }
    //使用toString方法输出
    public String toString() {
        return name+"\t"+price+"\\天"+"\t"+"载货:"+goods+"吨";
    }
}

主函数

package com.dadataxi;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class UserInter {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double totalPrice = 0;//订单总价格
        int totalPersons = 0;//订单总可坐人数
        double totalGoods = 0;//订单总可载货量
        Set<String> carPersons = new HashSet<String>();//存储载人车辆
        Set<String> carGoods = new HashSet<String>();//存储载货车辆
        Car cars[] = { new PersonCar("奥迪A4", 500.0, 4), new PiKa("皮卡", 200, 2, 1.2),
                new HuoChe("东风大货", 1000, 20) };//引用Car类型数组变量存储车辆
        //用户交互代码
        //获取用户输入
        Scanner in = new Scanner(System.in);
        System.out.println("--------欢迎使用答答租车系统--------");
        System.out.println("您是否要租车:1 是,2 否");
        String result = in.next();
        if (result.equals("1")) {
            System.out.println("序号" + "\t" + "汽车名称" + "\t" + "租金" + "\t" + "容量" + "\t");
            for (int i = 0; i < cars.length; i++) {
                System.out.println((i + 1) + "." + "\t" + cars[i]);
            }
            int flag = 1;
            String res1 = "1";
            do {
                if (res1.equals("1")) {
                    System.out.println("请输入要租车的车型");
                    int xuHao = in.nextInt();
                    System.out.println("请输入要租车的天数");
                    int days = in.nextInt();
                    System.out.println("请输入要租车的数量");
                    int num = in.nextInt();
                    totalPrice += cars[xuHao - 1].calcPrice(days, num);
                    if (cars[xuHao - 1].isGood) {
                        carGoods.add(cars[xuHao - 1].name);
                        totalGoods += cars[xuHao - 1].calcGoods(num);
                    }
                    if (cars[xuHao - 1].isPerson) {
                        carPersons.add(cars[xuHao - 1].name);
                        totalPersons += cars[xuHao - 1].calcPersons(num);
                    }
                    System.out.println("您是否继续租车:1 是 0 否");
                    res1 = in.next();
                } else if (res1.equals("0")) {
                    System.out.println("退出答答租车系统");
                    flag = 0;
                } else {
                    System.out.println("请输入正确的指令");
                }
            } while (flag == 1);
            System.out.println("--------您的账单:--------");
            if (carPersons.size() > 0) {
                System.out.println("---可载人车辆有:---");
                for (String name : carPersons) {
                    System.out.print(name + "\t");
                }
                System.out.print(totalPersons + "人" + "\n");
            }
            if (carGoods.size() > 0) {
                System.out.println("---可载货车辆有:---");
                for (String name : carGoods) {
                    System.out.print(name + "\t");
                }
                System.out.print(totalGoods + "吨" + "\n");              
            }
            System.out.println("---您的租车总价格:" + totalPrice + "元");
        } else if (result.equals("2")) {
            System.out.println("退出答答租车系统");
            System.exit(0);
        } else {
            System.out.println("请输入正确的指令");
        }
    }
}

有问题请多多指教

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