最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

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

我的嗒嗒租車系統(tǒng)----- 花了一下午做出來,還有很多不足,請(qǐng)大家指正~

package?com.imooc;

public?abstract?class?Car?{?//所有車的父類
	public??String?name;		//車名
	public?int?price;		//價(jià)格
	
	public?abstract?void?showInfo();	//抽象方法,子類繼承時(shí)重寫,顯示車名、價(jià)格、載客或載貨量

	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;
	}

}
package?com.imooc;

public?class?Auto?extends?Car?{	//汽車類
	public?String?name;
	public?int?price;
	public?int?capPerson;	//載客量
	
	public?Auto(String?name,int?price,int?capPerson){
		this.name=name;
		this.price=price;
		this.capPerson=capPerson;
	}
	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;
	}
	public?int?getCapPerson()?{
		return?capPerson;
	}
	public?void?setCapPerson(int?capPerson)?{
		this.capPerson?=?capPerson;
	}
	@Override
	public?void?showInfo()?{
		//?TODO?自動(dòng)生成的方法存根
		System.out.println(getName()?+?'\t'?+getPrice()?+"元/天"?+?'\t'?+?"載人:"+getCapPerson()?+"人");
	}

}
package?com.imooc;

public?class?Pickup?extends?Car?{	//皮卡類
	public?String?name;
	public?int?price;
	public?int?capPerson;	//載客量
	public?int?capThings;	//載貨量
	
	//構(gòu)造方法
	public?Pickup(String?name,int?price,int?capPerson,int?capThings){
		this.name?=?name;
		this.price?=?price;
		this.capPerson?=?capPerson;
		this.capThings?=?capThings;
	}
	
	
	
	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;
	}

	public?int?getCapPerson()?{
		return?capPerson;
	}

	public?void?setCapPerson(int?capPerson)?{
		this.capPerson?=?capPerson;
	}

	public?int?getCapThings()?{
		return?capThings;
	}

	public?void?setCapThings(int?capThings)?{
		this.capThings?=?capThings;
	}



	@Override
	public?void?showInfo()?{
		//?TODO?自動(dòng)生成的方法存根
		System.out.println(getName()?+?'\t'?+getPrice()?+"元/天"?+?'\t'?+?"載人:"+getCapPerson()?+"人"+?"??載貨:"+getCapThings()?+"噸");
	}

}
package?com.imooc;

public?class?Truck?extends?Car?{	//貨車類
	public?String?name;
	public?int?price;
	public?int?capThings;
	
	//構(gòu)造方法
	public?Truck(String?name,int?price,int?capThings){
		this.name?=?name;
		this.price?=?price;
		this.capThings?=?capThings;	//載貨量
	}
	
	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;
	}


	public?int?getCapThings()?{
		return?capThings;
	}


	public?void?setCapThings(int?capThings)?{
		this.capThings?=?capThings;
	}

	
	@Override
	public?void?showInfo()?{
		//?TODO?自動(dòng)生成的方法存根
		System.out.println(getName()?+?'\t'?+getPrice()?+"元/天"?+?'\t'?+?"載貨:"+getCapThings()?+"噸");
	}

}
package?com.imooc;

import?java.util.*;

public?class?DadaRent?{

	public?static?void?main(String[]?args)?{
		//?TODO?自動(dòng)生成的方法存根

//創(chuàng)建車輛信息
		Car[]?allRent?=?{new?Auto("奧迪A4",500,4),new?Auto("馬自達(dá)6",400,4),new?Pickup("皮卡雪6",450,4,2),new?Auto("金龍??",800,20),new?Truck("松花江",400,4),new?Truck("依維河",1000,20)};
		System.out.println("歡迎使用嗒嗒租車系統(tǒng):");
		System.out.println("您是否想要租車:1是??0否");

	
//顯示租車信息
		Scanner?input?=?new?Scanner(System.in);
		int?choice?=?input.nextInt();
		while(choice!=0||choice?!=1)
		{	//如果輸入不為0或1,則重新輸入
			if(choice?==0){
				System.out.println("感謝您使用嗒嗒租車系統(tǒng),下次再見!");
				break;
			}else?if(choice?==1){
				System.out.println("您可租車的類型及其價(jià)目表:");
				System.out.println("序號(hào)"?+?'\t'?+?"汽車名稱"?+?'\t'?+?"租金"?+?'\t'?+"容量");
				for(int?i=0;i<allRent.length;i++){
					System.out.print((i+1)?+?".\t");
					allRent[i].showInfo();
				}
				System.out.println("請(qǐng)輸入想要租車的數(shù)量:");
				break;
			}else?{
					System.out.println("請(qǐng)輸入正確的數(shù)字:1是??0否");
					choice?=?input.nextInt();
				}
			}
		
		int?carNum?=?input.nextInt();	//租車數(shù)量
		Car[]?choiceCar?=?new?Car[carNum];		//將客戶選擇的車輛對(duì)象放入choiceCar數(shù)組
		for(int?i=0;i<carNum;i++){
			System.out.println("請(qǐng)輸入第"?+?(i+1)?+"輛車的序號(hào):");
			int?num?=input.nextInt();//每輛車的序號(hào)
			choiceCar[i]=allRent[num-1];
		}
		
		System.out.println("請(qǐng)輸入想要租車的天數(shù):");
		int?rentDay?=?input.nextInt();??//租車天數(shù)
		
		
//計(jì)算并顯示賬單
		System.out.println("********************您的賬單信息如下:********************");
		int?dayPrice=0;	//每天租車總價(jià)
		
		
		System.out.println(">>>>>>>您要租的車是:???");
			for(int?i=0;i<choiceCar.length;i++){
				dayPrice=choiceCar[i].getPrice()+dayPrice;

				choiceCar[i].showInfo();
			}
			//System.out.println("每天總價(jià):"+dayPrice);
		System.out.println(">>>>>>>您總共要租借:??"?+?rentDay??+?"??天");
		
//計(jì)算總載客載貨量
		int?totalCapPerson?=?0;		//總載客量
		int?totalCapThings?=?0;		//總載貨量
		for(int?i?=?0;?i?<?choiceCar.length;?i++){
			//判斷所選車是Auto、Truck還是Pickup
			if(choiceCar[i]?instanceof?Auto){	//汽車載客量
				totalCapPerson?+=?((Auto)choiceCar[i]).getCapPerson();?
			}
			
			if(choiceCar[i]?instanceof?Truck){	//貨車載貨量
				totalCapThings?+=?((Truck)choiceCar[i]).getCapThings();
			}
			
			if(choiceCar[i]?instanceof?Pickup){		//皮卡載客和載貨量
				totalCapPerson?+=((Pickup)choiceCar[i]).getCapPerson();
				totalCapThings?+=((Pickup)choiceCar[i]).getCapThings();
			}
		}
		
		//輸出總載貨量和總載客量
		System.out.println(">>>>>>>您所要租借的總載客量為:?"?+?totalCapPerson?+?"人\t"?+?"總載貨量為:"?+?totalCapThings?+?"噸");
		int?totalPrice?=?dayPrice*rentDay;	//總價(jià)
		System.out.println(">>>>>>>您總共需要支付:??"?+?totalPrice??+?"??元");
		System.out.println("感謝您使用嗒嗒租車系統(tǒng),下次再見!");
		input.close();
	}
	

	
}


正在回答

27 回答

寫的不錯(cuò)哦~~學(xué)習(xí)了……將客戶選擇的車輛對(duì)象放入choiceCar數(shù)組這點(diǎn)很棒,我就覺得自己學(xué)的太死板了

提點(diǎn)小建議:

1、樓主的instanceof用法不是特別推薦啊,沒有好好利用面向?qū)ο笾械亩鄳B(tài)性,可以在父類里面直接定義屬性——載客量和載貨量

2、還有關(guān)于異常的處理,如果能加上就更完美了~~~


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

biofool_0001 提問者

非常感謝!
2015-04-28 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慕粉3904766

想問下不用instanceof怎么分類?他最后要輸出“可載人的車有:xxxx 總載客量:xxxxx”。
2016-09-04 回復(fù) 有任何疑惑可以回復(fù)我~
#3

慕雪0737679 回復(fù) 慕粉3904766

可以看看我寫的
2017-10-11 回復(fù) 有任何疑惑可以回復(fù)我~

choiceCar[i]=allRent[num-1]; ? 請(qǐng)問這一句可以解釋一下嗎


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

厲害,我最近也在看慕客網(wǎng),菜鳥階段,大三了,希望好好學(xué)習(xí)一下,請(qǐng)多幫助。

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

好多病句!整個(gè)抄下來了!不過還是謝謝了!我一點(diǎn)不會(huì)寫!最重要的你沒抓dayprice!暈

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

為什么我自己寫的是這樣的?

http://img1.sycdn.imooc.com//59872c0e0001052e07450352.jpg

0 回復(fù) 有任何疑惑可以回復(fù)我~
這個(gè)程序有不足的地方嗎??子類中可以不寫父類里的屬性了

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

要輸出序號(hào)的時(shí)候,輸出的序號(hào)數(shù)大于車的數(shù)量這個(gè)怎么沒有加個(gè)判斷?

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

感謝樓主的代碼,給了很大的啟發(fā)。不然都覺得無從下手

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

謝謝?? 非常好

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

我想了一下午都沒想好怎么寫。。。

0 回復(fù) 有任何疑惑可以回復(fù)我~
首頁上一頁123下一頁尾頁

舉報(bào)

0/150
提交
取消
Java入門第二季
  • 參與學(xué)習(xí)       531268    人
  • 解答問題       6327    個(gè)

課程升級(jí)!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙

進(jìn)入課程

我的嗒嗒租車系統(tǒng)----- 花了一下午做出來,還有很多不足,請(qǐng)大家指正~

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

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

幫助反饋 APP下載

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

公眾號(hào)

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