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

為了賬號安全,請及時綁定郵箱和手機立即綁定

慕課答答租車作業(yè)

標簽:
Java
package 面向对象.慕课作业嗒嗒租车;

import java.util.Scanner;

public class Car {

    int id;
    int rent;
    int seat;
    int weight;
    String brand;
    // 构造器
    public Car(int id, String brand, int rent, int seat, int weight){
        this.id = id;
        this.brand = brand;
        this.rent = rent;
        this.seat = seat;
        this.weight = weight;
    }

    // 规范打印输出格式,使信息对齐
    public void showInfo(){
        if (this.weight == 0){
            if (this.rent < 800)
                System.out.println(this.id + ".\t\t" + this.brand + "\t\t" + this.rent + "元/天" + "\t\t载人:" + seat);
            else
                System.out.println(this.id + ".\t\t" + this.brand + "\t\t\t" + this.rent + "元/天" + "\t\t载人:" + seat);
        }
        else if (this.seat == 0)
            if (this.rent < 1000)
                System.out.println(this.id + ".\t\t" + this.brand + "\t\t" + this.rent + "元/天" + "\t\t载货:" + weight);
            else
                System.out.println(this.id + ".\t\t" + this.brand + "\t\t" + this.rent + "元/天" + "\t载货:" + weight);
        else
            System.out.println(this.id + ".\t\t" + this.brand + "\t\t" + this.rent + "元/天" + "\t\t载人:" + seat + " 载货:" + weight);
    }
    // main 方法入口
    public static void main(String[] args) {
        // 向上转型表现多态
        Car[] cars = {new PassengerCar(1, "奥迪A4", 500, 4),
                      new PassengerCar(2, "马自达6", 400, 4),
                      new Pickup(3, "皮卡雪6", 450, 4, 4),
                      new PassengerCar(4, "金龙", 800, 20),
                      new Truck(5, "松花江", 400, 4),
                      new Truck(6, "依维柯", 1000, 20)
        };

        Scanner scan = new Scanner(System.in);

        System.out.println("- - - - -欢迎使用答答租车系统- - - - -");
        System.out.println("您是否要租车:1、是  2、否");

        String s = scan.nextLine();
        if (s.equals("1")){
            // 打印所有车型
            System.out.println("您可租车的类型及其价目表:");
            System.out.println("序号 \t汽车名称\t\t租金\t\t\t容量");
            for (Car car : cars)
                car.showInfo();

            // 询问租车具体情况
            int totalRentNumber;
            int rentDays;
            int totalSeat = 0;
            int totalWeight = 0;
            int cost = 0;
            int rentId;
            String infoForSeat = "";
            String infoForWeight = "";

            System.out.println("请输入您要租车的数量");
            totalRentNumber = scan.nextInt();

            for (int i = 1; i <= totalRentNumber; i++){
                System.out.println("请输入第" + i + "辆车的序号:");
                rentId = scan.nextInt();

                if (cars[rentId-1].seat != 0 && cars[rentId-1].weight == 0)
                    infoForSeat += cars[rentId-1].brand + " ";
                else
                    infoForWeight += cars[rentId-1].brand + " ";

                totalSeat += cars[rentId-1].seat;
                totalWeight += cars[rentId-1].weight;
                cost += cars[rentId-1].rent;
            }

            System.out.println("请输入租车天数:");
            rentDays = scan.nextInt();

            // 打印所有结果
            System.out.println("您的账单:");
            System.out.println("***可载人的车有:\n" + infoForSeat + "共载人:" + totalSeat + "个");
            System.out.println("***可载货的车有:\n" + infoForWeight + "共载货:" + totalWeight + "吨");
            System.out.println("租车总价格:" + cost*rentDays + "元");

            scan.close();
            System.out.println("欢迎您的使用!下次再见!");

        }else
            System.out.println("欢迎您的使用!下次再见!");

    }
}

class  PassengerCar extends Car{

    public PassengerCar(int id, String brand, int rent, int seat){
        super(id, brand, rent, seat, 0);
    }
}

class Truck extends Car{

    public Truck(int id, String brand, int rent, int weight){
        super(id, brand, rent, 0, weight);
    }
}

class Pickup extends Car{

    public Pickup(int id, String brand, int rent, int seat, int weight){
        super(id, brand, rent, seat, weight);
    }
}


點擊查看更多內容
1人點贊

若覺得本文不錯,就分享一下吧!

評論

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

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

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消