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

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

自己的剛寫的代碼 寫的不好 但是可以給幕友作為借鑒

好久沒有敲代碼了 變得生疏和腦子不夠用了 用慕課來重溫下知識(shí)點(diǎn)還是很好的 這是我在看了老師解題所給出的部分代碼后自己補(bǔ)上的 每個(gè)類都用橫線分隔開了 主要由5個(gè)類組成 一個(gè)父類Car 三個(gè)子類Truck、PickUp、PassengerCar 和一個(gè)主函數(shù)類Main組成 本人寫的代碼很爛 寫在這里只是給更多幕友一個(gè)參考的地方 也說不上參考就是給大家隨便看下?

-------------------------

package com.demo_h;

public class Car {

protected String name;

protected double rent;


public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getRent() {

return rent;

}

public void setRent(double rent) {

this.rent = rent;

}

}

-----------------------------------

package com.demo_h;

public class Truck extends Car {

private double cargoCapacity;

public Truck(String name,double rent,double cargoCapacity)

{

this.name = name;

this.rent = rent;

this.setCargoCapacity(cargoCapacity);

}


public void setCargoCapacity(double cargoCapacity) {

this.cargoCapacity = cargoCapacity;

}


public double getCargoCapacity() {

return cargoCapacity;

}


}

--------------------------------

package com.demo_h;

public class PickUp extends Car {

private double peopleCapacity;

private double cargoCapacity;

public PickUp(String name,double rent,double peopleCapacity,double cargoCapacity)

{

this.name = name;

this.rent = rent;

this.setPeopleCapacity(peopleCapacity);

this.setCargoCapacity(cargoCapacity);

}


public void setCargoCapacity(double cargoCapacity) {

this.cargoCapacity = cargoCapacity;

}


public double getCargoCapacity() {

return cargoCapacity;

}


public void setPeopleCapacity(double peopleCapacity) {

this.peopleCapacity = peopleCapacity;

}


public double getPeopleCapacity() {

return peopleCapacity;

}

}

---------------------------------

package com.demo_h;

public class PassengerCar extends Car {

private double peopleCapacity;

public PassengerCar(String name,double rent,double peopleCapacity)

{

this.name = name;

this.rent = rent;

this.peopleCapacity = peopleCapacity;

}


public double getPeopleCapacity() {

return peopleCapacity;

}


public void setPeopleCapacity(double peopleCapacity) {

this.peopleCapacity = peopleCapacity;

}

}

------------------------------------

package com.demo_h;

import java.util.Scanner;

public class Main {

/*

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

//用父類數(shù)組指向子類實(shí)例化對(duì)象,并且用構(gòu)造方法賦值

Car[] carsForRent = {new PassengerCar("奧迪", 500, 4),new PassengerCar("馬自達(dá)", 400, 4),

new PassengerCar("金龍", 800, 20),new PickUp("皮卡雪", 450, 4, 2),

new Truck("松花江", 400, 4),new Truck("依維柯", 1000, 20)};

System.out.println("****歡迎來到答答租車系統(tǒng)****");

System.out.println("你是否要租車:1是 ?0否");

Scanner scan = new Scanner(System.in);

String input = scan.next();

if(input.equals("1"))

{

System.out.println("你可租車的類型及其價(jià)目表:");

System.out.println("序號(hào)\t汽車名稱\t租金\t容量");

int i = 1;

//顯示所有的車型

for(Car currentCar:carsForRent)//foreach循環(huán)顯示數(shù)組內(nèi)容

{

if(currentCar instanceof PassengerCar)//判斷是否指向當(dāng)前子類對(duì)象,然后進(jìn)行向下轉(zhuǎn)型

{

System.out.println(i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()

+"元/天\t載人"+(int)((PassengerCar) currentCar).getPeopleCapacity()+"人");

i++;

}

if(currentCar instanceof Truck)

{

System.out.println(i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()

+"元/天\t載貨"+((Truck) currentCar).getCargoCapacity()+"噸");

i++;

}

if(currentCar instanceof PickUp)

{

System.out.println(i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()

+"元/天\t載人"+(int)((PickUp) currentCar).getPeopleCapacity()+"人.載貨"+

((PickUp) currentCar).getCargoCapacity()+"噸");

i++;

}

}

System.out.println("請(qǐng)輸入您要汽車的數(shù)量");

int carNum = scan.nextInt();

int accout = 0;

int peopleNum = 0;

int cargoNum = 0;

Car[] carsForRent01 = new Car[carNum]; //此數(shù)組方便為打印車輛名字而建

if(carNum>0&&carNum<7)//限制汽車數(shù)量

{

for(int a=0;a<carNum;a++)

{

System.out.println("請(qǐng)輸入第"+(a+1)+"輛車的序號(hào)");

int num = scan.nextInt();

switch (num) { //用switch語句實(shí)現(xiàn)選擇以及對(duì)金額、載客量和數(shù)組的賦值

case 1:

accout = accout+500;

peopleNum = peopleNum+4;

carsForRent01[a] = carsForRent[0];

break;

case 2:

accout = accout+400;

peopleNum = peopleNum+4;

carsForRent01[a] = carsForRent[1];

break;

case 3:

accout = accout+450;

peopleNum = peopleNum+4;

cargoNum = cargoNum+2;

carsForRent01[a] = carsForRent[2];

break;

case 4:

accout = accout+800;

peopleNum = peopleNum+20;

carsForRent01[a] = carsForRent[3];

break;

case 5:

accout = accout+400;

cargoNum = cargoNum+4;

carsForRent01[a] = carsForRent[4];

break;

case 6:

accout = accout+1000;

cargoNum = cargoNum+20;

carsForRent01[a] = carsForRent[5];

break;

default:

System.err.println("輸入車輛序號(hào)不符合標(biāo)準(zhǔn)!");

break;

}

}

}

else

{

System.out.println("輸入汽車數(shù)量過大或則不符合標(biāo)準(zhǔn)!");

}

System.out.println("*****你的賬單*****");

System.out.println("---可載客的車有---");

for(Car currentCar:carsForRent01) //輸出可載客車的名字 注意進(jìn)行對(duì)象比較

{

if(currentCar instanceof PassengerCar)

{

System.out.print(currentCar.getName()+" ?");

}

}

System.out.println("共載人:"+peopleNum+"人");

System.out.println("---可載貨的車有---");

for(Car currentCar:carsForRent01)

{

if((currentCar instanceof Truck)||(currentCar instanceof PickUp))

{

System.out.print(currentCar.getName()+" ?");

}

}

System.out.println("共載貨:"+cargoNum+"噸");

System.out.println("租車總價(jià)格:"+accout+"¥");

}

else

{

System.out.println("退出系統(tǒng) 歡飲下次光臨!");

System.exit(-1);

}


}


}


正在回答

6 回答

Car數(shù)組的類型呢?

int 還是String?

表示完全懵逼了,

下面感覺很難看懂,至少給個(gè)注釋呀。

跪謝。

0 回復(fù) 有任何疑惑可以回復(fù)我~

。。子類的構(gòu)造方法初始化都是錯(cuò)的吧?父類的私有成員需要調(diào)用方法設(shè)置,子類自己的私有成員才可以用(this。)的形式吧?!

0 回復(fù) 有任何疑惑可以回復(fù)我~

沒有寫租車天數(shù)

1 回復(fù) 有任何疑惑可以回復(fù)我~

應(yīng)該用arraylist方法收集客戶需要的車輛,如果要租兩輛奧迪,則該程序無法解決。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

威哥好牛逼

arraylis是什么作用
2015-08-22 回復(fù) 有任何疑惑可以回復(fù)我~

您好,我的是jdk1.8.0_45,但在eclipse創(chuàng)建工程時(shí)如下,使用foreach仍提示source level需要1.5以上。請(qǐng)問應(yīng)該下

http://img1.sycdn.imooc.com//55a76a350001808905360361.jpg

載那個(gè)版本的jdk呢,謝謝!

0 回復(fù) 有任何疑惑可以回復(fù)我~

謝謝您的分享!我的eclipse使用foreach時(shí)提示錯(cuò)誤,提示只有1.5以上的才能用,請(qǐng)問如何升級(jí)呢?

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

demo_h 提問者

下載jdk1.6版本,然后把原先老版本的1.5版本卸載掉,重新eclipse它會(huì)自動(dòng)搜索到新的jdk
2015-07-16 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

自己的剛寫的代碼 寫的不好 但是可以給幕友作為借鑒

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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