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

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

java入門第二季實戰(zhàn)

標(biāo)簽:
C

```//父类
package com.buaa.car;

public class Car {
protected int id;
protected String name;
protected int price;

public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
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;
}   

@Override
public String toString() {
    // TODO Auto-generated method stub
    return "车名:"+name+",租金:"+price+"元";
}

}
子类
``package com.buaa.car;

import com.buaa.car.impl.Zaihuo;
import com.buaa.car.impl.Zaike;

public class PickUp extends Car implements Zaike,Zaihuo{

public PickUp() {
    name = "F150";
    price = 5000;
}

@Override
public double cargo() {
    int weight = 3;
    return weight;
}

@Override
public int passengers() {
    int num = 5;
    return num;
}
@Override
public String toString() {
    // TODO Auto-generated method stub
    return super.toString()+"载重:"+cargo()+"吨,载客:"+passengers()+"人";
}

}


package com.buaa.car;

import com.buaa.car.impl.Zaike;

public class Bus extends Car implements Zaike{
    public Bus(){

        name = "宇通";
        price = 6000;
    }
    @Override
    public int passengers() {
        int num = 45 ;
        return num;
    }
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return super.toString()+"载客量:"+passengers()+"人";
    }
}

```输入代码
package com.buaa.car;

import com.buaa.car.impl.Zaihuo;

public class Truck extends Car implements Zaihuo{

    public Truck(){

        name = "擎天柱";
        price = 8000;
    }

    @Override
    public double cargo() {
        int weight = 25;
        return weight;
    }
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return super.toString()+"载重:"+cargo()+"吨";
    }
}
业务逻辑
``package com.buaa.main;

import java.util.Scanner;

import com.buaa.car.Bus;
import com.buaa.car.Car;
import com.buaa.car.PickUp;
import com.buaa.car.Truck;

public class Main {
    static int totalPrice = 0;
    static int totalCargo = 0;
    static int totalPass = 0;
    static Scanner input1;
    static Scanner input2;
    static Car[] c;

    public static void main(String[] args) {

        // 欢迎页
        System.out.println("选择租车类型");
        c = new Car[] { new Bus(), new Truck(), new PickUp() };
        int count = 0;
        // 遍历所有的车
        for (Car List : c) {
            count++;
            System.out.println(count + ":" + List.toString());
        }
        System.out.print("请输入选择车型:    ");
        input1 = new Scanner(System.in);
        int type = input1.nextInt();
        if (type > 0 && type <= c.length) {
            choose(type);
        } else {
            System.out.println("请输入正确的编号!");
            main(args);
        }
    }

    public static void choose(int type) {

        System.out.print("请输入租赁数量:    ");
        input2 = new Scanner(System.in);
        int num = input2.nextInt();
        if (type == 1) {
            Bus b = new Bus();
            totalPrice = (int) b.getPrice() * num;
            totalPass = b.passengers() * num;
            System.out.println("租用大巴" + num + "辆,共" + totalPrice + "元,可载客" + totalPass + "人");
        }
        if (type == 2) {
            Truck t = new Truck();
            totalPrice = (int) t.getPrice() * num;
            totalCargo = (int) t.cargo() * num;
            System.out.println("租用大巴" + num + "辆,共" + totalPrice + "元,可载重" + totalCargo + "吨");
        }
        if (type == 3) {
            PickUp p = new PickUp();
            totalPrice = (int) p.getPrice() * num;
            totalCargo = (int) p.cargo() * num;
            totalPass = p.passengers() * num;
            System.out.println("租用大巴" + num + "辆,共" + totalPrice + "元,可载重" + totalCargo + "吨,可载客" + totalPass + "人");
        }

    }
}
點擊查看更多內(nèi)容
7人點贊

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

評論

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

正在加載中
學(xué)生
手記
粉絲
0
獲贊與收藏
40

關(guān)注作者,訂閱最新文章

閱讀免費教程

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

100積分直接送

付費專欄免費學(xué)

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

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

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

幫助反饋 APP下載

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

公眾號

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

舉報

0/150
提交
取消