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

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

Java入門(mén)第二季課程——綜合練習(xí)

標(biāo)簽:
Java

父类:
package com.imooc;

public class Transport {
String name;
double rent;
double cargo;
int people;
public String getName(){
return name;
}
public double getRent(){
return rent;
}
public double getPeople(){
return people;
}
public double getCargo(){
return cargo;
}
}


子类1:
package com.imooc;

public class PassengerCar extends Transport {
private double people;
public PassengerCar(String name, double rent, int people){
this.name = name;
this.rent = rent;
this.people = people;
}
public double getPeople(){
return people;
}
}


子类2:
package com.imooc;

public class Truck extends Transport {
private double cargo;
public Truck(String name, double rent, double cargo){
this.name = name;
this.rent = rent;
this.cargo = cargo;
}
public double getCargo(){
return cargo;
}
}


子类3:
package com.imooc;

public class PickUp extends Transport {
private double cargo;
private double people;
public PickUp(String name, double rent, double cargo, int people){
this.name = name;
this.rent = rent;
this.cargo = cargo;
this.people = people;
}
public double getCargo(){
return cargo;
}
public double getPeople(){
return people;
}
}


主类:
package com.imooc;

import java.util.Scanner;
public class Initial {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Transport[] cars = {new PassengerCar("奥迪A4",500,4),new PassengerCar("马自达6",400,4),new Truck("东风",600,20),new Truck("奥拓",200,5),new PickUp("JEEP",500,2,4)};
    System.out.println("欢迎使用答答租车系统:");
    System.out.println("您是否要租车:1是  0否");
    Scanner s = new Scanner(System.in);
    String str = s.nextLine();
    if(Integer.parseInt(str)==1){
        //打印出数据表格
        System.out.println("您可租车的类型及其价目表:");
        System.out.println("序号\t汽车名称\t租金\t容量");
        int i = 1;
        for(Transport car:cars){
            if(car instanceof PassengerCar){
                System.out.println(""+i+"\t"+car.getName()+"\t"+car.getRent()+"元/天"+"\t"+"载人:"+car.getPeople()+"人");
            }
            if(car instanceof Truck){
                System.out.println(""+i+"\t"+car.getName()+"\t"+car.getRent()+"元/天"+"\t"+"载货:"+car.getCargo()+"吨");
            }
            if(car instanceof PickUp){
                System.out.println(""+i+"\t"+car.getName()+"\t"+car.getRent()+"元/天"+"\t"+"载人:"+car.getPeople()+"人"+"  "+"载货:"+car.getCargo()+"吨");
            }
            i++;
        }

        //租车数
        System.out.println("请输入您要租汽车的数量:");
        int num = s.nextInt();
        int[] n = new int[num];
        for(int j=0; j<num; j++){
            System.out.println("请输入第"+(j+1)+"辆车的序号:");
            int t = s.nextInt();
            if(t <= cars.length){
                n[j] = t;
            }else{
                j--;
            }
        }

        //租车天数
        System.out.println("请输入租车天数:");
        int day = s.nextInt();

        //输出结果
        System.out.println("您的账单:");
        //载人车名及总载人数
        System.out.println("***可载人的车有:");
        int sumPeople = 0;
        for(int j=0; j<num; j++){
            if(cars[n[j]-1] instanceof PassengerCar || cars[n[j]-1] instanceof PickUp){
                System.out.print(cars[n[j]-1].name+"\t");
                sumPeople += cars[n[j]-1].getPeople();
            }
        }
        System.out.println("共载人:"+sumPeople+"人");
        //载货车名及总载货量
        System.out.println("***可载货的车有:");
        double sumCargo = 0;
        for(int j=0; j<num; j++){
            if(cars[n[j]-1] instanceof Truck || cars[n[j]-1] instanceof PickUp){
                System.out.print(cars[n[j]-1].name+"\t");
                sumCargo += cars[n[j]-1].getCargo();
            }
        }
        System.out.println("共载货:"+sumCargo+"吨");
        //总费用
        double value = 0;
        for(int j=0; j<num; j++){
            value += cars[n[j]-1].rent;
        }
        double sumValue = day*value;
        System.out.println("***租车总价格:"+sumValue+"元");
    }
    s.close();
}

}

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

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

評(píng)論

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

正在加載中
感謝您的支持,我會(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
提交
取消