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

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

java第二季6.1綜合練習(xí)

標(biāo)簽:
Java

import java.util.Scanner;
public class Text1 {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        Car[] carforrent={new CarryPeople("奥迪A4",500,4),
                          new CarryPeople("马自达", 400, 4),
                          new CarryC_P("皮卡雪6", 450, 4, 2),
                          new CarryPeople("金龍", 800, 20),
                          new CarryCargo("松花江", 400, 4),
                          new CarryCargo("依維柯", 1000, 20)};
        String question="T";
        Car car=new Car();
        do{
        System.out.println("欢迎使用達達租車系統!");
        System.out.println("您是否要租车?(T/F)");
        String choice=input.next();
        if(choice.equalsIgnoreCase("T")){
            System.out.println("序号\t"+"汽车名称\t"+"租金\t\t"+"容量");
            int i=1;
            for(Car c:carforrent){
                System.out.print(i+".\t");
                if(c instanceof CarryCargo){
                ((CarryCargo)c).information();}
                if(c instanceof CarryPeople){
                ((CarryPeople)c).information();}
                if(c instanceof CarryC_P){
                ((CarryC_P)c).information();}
            //不能用c.information()因为c是属于Car数组的一个变量而已
                i++;
            }
            System.out.println("請輸入要租用車輛的數量:");
            int carnumber=input.nextInt();
            int N[]=new int[carnumber];
            for(int j=0;j<carnumber;j++){
                System.out.println("請輸入第"+(j+1)+"輛租用車輛:");
                N[j] = input.nextInt();
            }
            System.out.println("請輸入組訂的天數:");
            int days=input.nextInt();
            System.out.println("您的訂單為:\n"+"***************可載人車輛***************");
            String message=""; 
            int peototal=0;
            for(int a=0;a<N.length;a++){
                if(carforrent[N[a]-1] instanceof CarryCargo){
                }
                if(carforrent[N[a]-1] instanceof CarryPeople){
                message+=((CarryPeople) carforrent[N[a]-1]).getName()+" ";
                peototal+=((CarryPeople) carforrent[N[a]-1]).numofpeo;
                } 
                if(carforrent[N[a]-1] instanceof CarryC_P){
                message+=((CarryC_P) carforrent[N[a]-1]).getName()+" ";
                peototal+=((CarryC_P) carforrent[N[a]-1]).numofpeo;
                }
            }
            System.out.println(message+" 共載人:"+peototal);
            System.out.println("***************可載貨車輛***************");
            message="";
            int cargototal=0;
            for(int a=0;a<N.length;a++){
                if(carforrent[N[a]-1] instanceof CarryCargo){
                message=message+((CarryCargo) carforrent[N[a]-1]).getName()+" ";
                cargototal+=((CarryCargo) carforrent[N[a]-1]).cargo;
                }
                if(carforrent[N[a]-1] instanceof CarryPeople){

                } 
                if(carforrent[N[a]-1] instanceof CarryC_P){
                message=message+((CarryC_P) carforrent[N[a]-1]).getName()+" ";
                cargototal+=((CarryC_P) carforrent[N[a]-1]).cargo;
                }
            }
            System.out.println(message+" 共載貨:"+cargototal);
            System.out.println("總租金為:");
            double renttotal=0;
            for(int a=0;a<N.length;a++){
                if(carforrent[N[a]-1] instanceof CarryCargo){
                    renttotal+=((CarryCargo) carforrent[N[a]-1]).getRentMoney()*days;
                }
                if(carforrent[N[a]-1] instanceof CarryPeople){
                    renttotal+=((CarryPeople) carforrent[N[a]-1]).getRentMoney()*days;
                } 
                if(carforrent[N[a]-1] instanceof CarryC_P){
                    renttotal+=((CarryC_P) carforrent[N[a]-1]).getRentMoney()*days;
                }
            }
            System.out.println(renttotal);
            System.out.println("您還想再次使用達達租車系統嗎?(T/F)");
            question=input.next();
        }
        else {
            question="F";
            System.out.print("再见!");
        }

        }while(question.equalsIgnoreCase("T"));
        System.out.println("達達租車:謝謝您的光臨,祝您生活愉快!");
    }
   }

public class Car {
  protected  String name;
  protected double money;
  protected int cargo,numofpeo;
  Car(){
      }
 void setName(String name) {
     this.name=name;
}
 String getName() {
    return name;
}
 void setRentMoney(double money) {
     this.money=money;
}
double getRentMoney() {
    return money;
}
}   

public class CarryCargo extends Car {
    public CarryCargo(String name,double money,int cargo) {
     this.name=name;
     this.money=money;
     this.cargo=cargo;
    }
    void information(){
        System.out.println(name + "\t" + money + "元一天\t" + "载货:" + cargo + "吨");
    }

    void setCargo(int cargo){
        this.cargo=cargo;
    }
    int getCargo(){
    return cargo;   
    }
}

public class CarryPeople extends Car {
    public CarryPeople(String name, double money, int numofpeo) {
        this.name = name;
        this.money = money;
        this.numofpeo = numofpeo;
    }

    void information() {
        System.out.println(name + "\t" + money + "元一天\t" + "载人:" + numofpeo
                + "人");
    }

    void setNumofpeo(int numofpeo) {
        this.numofpeo = numofpeo;
    }

    int getNumofpeo() {
        return numofpeo;
    }

}

public class CarryC_P extends Car {
    public CarryC_P(String name, double money, int numofpeo, int cargo) {
        this.name = name;
        this.money = money;
        this.numofpeo = numofpeo;
        this.cargo = cargo;
    }

    void information() {
        System.out.println(name + "\t" + money + "元一天\t" + "载人:" + numofpeo
                + "人 载货:" + cargo + "吨");
    }

    void setNumofpeo(int numofpeo) {
        this.numofpeo = numofpeo;
    }

    int getNumofpeo() {
        return numofpeo;
    }

    void setCargo(int cargo) {
        this.cargo = cargo;
    }

    int getCargo() {
        return cargo;
    }
}
點(diǎn)擊查看更多內(nèi)容
4人點(diǎn)贊

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

評論

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

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

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

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

立即參與 放棄機(jī)會
微信客服

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

幫助反饋 APP下載

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

公眾號

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

舉報(bào)

0/150
提交
取消