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

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

看了n遍視頻終于搞出來了,感覺前面學(xué)的終于沒那么模糊了

package?project.Car;
public?abstract?class?Car?{
??String?name;	
??double?price;	
??int?person,?cargo;
??
??int?getCargo()?{
??	return?0;	
??}
??int?getPerson()?{
??	return?0;
??}
}
public?class?CargoCar?extends?Car{???????????????????????????????????//裝貨
	private?int?cargo;
	public?CargoCar(String?name,?double?price,?int?cargo)?{
		this.name?=?name;		
		this.price?=?price;		
		this.setCargo(cargo);	
	}
	public?int?getCargo()?{
		return?cargo;	
	}	
	public?void?setCargo(int?cargo)?{
		this.cargo?=?cargo;	
	}	
}
public?class?PassengerCar?extends?Car?{???????????????????????????????????????????????//載人
	private?int?person;
	public?PassengerCar(String?name,?double?price,?int?person)?{
		this.name?=?name;
		this.price?=?price;		
		this.setPerson(person);	
	}
	public?int?getPerson()?{
		return?person;	
	}	
	public?void?setPerson(int?person)?{
		this.person?=?person;	
	}
}
public?class?PickupCar?extends?Car{?????????????????????????????//皮卡
	private?int?person;		
	private?int?cargo;	
	public?PickupCar(String?name,?double?price,?int?person,?int?cargo)?{
		this.name?=?name;
		this.price?=?price;
		this.person?=?person;	
		this.cargo?=?cargo;	
	}	
	public?int?getPerson()?{
		return?person;	
	}	
	public?void?setPerson(int?person)?{	
		this.person?=?person;	
	}	
	public?int?getCargo()?{
		return?cargo;	
	}	
	public?void?setCargo(int?cargo)?{		
	????????this.cargo?=?cargo;
	}
}	
package?project.Car;
import?java.util.Scanner;?
public?class?Car_Rent?{
	static?double?Price,?num_Cargo;??????//Price為總價(jià)格,?num_Cargo為總貨物量
	static?int?num_Person;???????????//num_Person為可載總?cè)藬?shù)
	public?static?void?main(String[]?args)?{
		if?(askFirst()?==?1)?{		
			Car[]?car?=?{new?PassengerCar("奧迪A4",?500,?4),?new?PassengerCar("馬自達(dá)6",?400
			,?4),?new?PickupCar("皮卡雪6",?450,?4,?2),new?PassengerCar("金龍",?800,?20),?
			new?CargoCar("松花江",?400,?4),?new?CargoCar("依維柯",?1000,?20)
			};
			show(car);	
			askSecond(car);	
		}
	}
	static?int?askFirst()?{?????????//判斷是否租車
		System.out.println("歡迎使用租車系統(tǒng):");
		System.out.println("您是否要租車:1是?0否");
		Scanner?input?=?new?Scanner(System.in);
		int?judge?=?input.nextInt();	
		return?judge;
	}	
	static?void?show(Car[]?car)?{??????//展示價(jià)目表,\t制表符,橫向跳8個(gè)空格
		System.out.println("您可租車的類型及其價(jià)目表:\n序號(hào)\t汽車名稱\t\t租車\t\t容量");
		for(int?i?=?0;?i?<?car.length;?i++)?{
			if?(car[i].person?>?0?&&?car[i].cargo?>?0)?{
				System.out.println((i+1)+".\t"+car[i].name+"\t\t"+car[i].price+"元/天\t?"+
				"載人:"+car[i].person+"人?"+"載貨:"+car[i].cargo+"噸");
			}
			else?if?(car[i].person?>?0)?{
				System.out.println((i+1)+".\t"+car[i].name+"\t\t"+car[i].price+"元/天\t"+
				"載人:"+car[i].person+"人?");
			}			
			else?{
				System.out.println((i+1)+".\t"+car[i].name+"\t\t"+car[i].price+"元/天\t"+
				"載貨:"+car[i].cargo+"噸");	
			}		
		}			
	}	
	static?void?askSecond(Car[]?car)?{
		System.out.println("請輸入您要租汽車的數(shù)量:");	
		Scanner?input?=?new?Scanner(System.in);	
		int?num?=?input.nextInt();???????????????????????//num為租車數(shù)量	
		int[]?recode?=?new?int[num];?????????????????????//recode數(shù)組記錄所租車輛的編號(hào),tag是該數(shù)組編號(hào)
		int?tag?=?0;?		
		for?(int?i?=?1;?i?<=?num;?i++){?????????????//輸入所租車輛序號(hào),更新總價(jià)格和載貨量,載人數(shù)等數(shù)據(jù)
		System.out.println("請輸入第"+i+"輛車的序號(hào):");
		int?code?=?input.nextInt();	
		recode[tag++]?=?code-1;			
		Price?+=?car[code-1].price;			
		num_Cargo?+=?car[code-1].getCargo();			
		num_Person?+=?car[code-1].getPerson();		
	}		
????????	System.out.println("請輸入租車天數(shù):");		
????????	int?days?=?input.nextInt();		
????????	Price?*=?days;		
????????	System.out.println("您的賬單:\n***可載人的車有:");		
????????	for(int?temp?=?0;?temp?<?tag;?temp++)?{		
????????		if?(car[recode[temp]].getPerson()?>?0)?{????????//輸出能載人的車的name,下面同理	
????????			System.out.print(car[recode[temp]].name+"?");	
????????		}?		
????????	}		
????????	System.out.println("共載人:"+num_Person+"人");		
????????	System.out.println("***載貨的車有:");		
????????	for(int?temp?=?0;?temp?<?tag;?temp++)?{		
????????		if?(car[recode[temp]].getCargo()?>?0)?{		
????????			System.out.print(car[recode[temp]].name+"?");			
????????		}		
????????	}		
????????	System.out.println("共載貨:"+num_Cargo+"噸");		
????????	System.out.println("***租車總價(jià)格:"+Price+"元");			
	}
}

https://img1.sycdn.imooc.com//5cd284ed00015aba04120499.jpg

正在回答

3 回答

你前面在CargoCar類,PassengerCar類和PickupCar類里面把person和cargo設(shè)置為private,在下面的main方法里面又直接調(diào)用了這兩個(gè)屬性而不是通過get方法來獲取,所以輸出的結(jié)果容量都是0

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

程序展示? 載貨怎么都是0啊

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

請教一個(gè)問題,我把方法寫到主類里面了,你這是都寫到主方法里面的吧?這兩種方式哪個(gè)更好一點(diǎn)呢?

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

慕姐0352535 提問者

我的主方法里也只是方法調(diào)用啊
2019-05-09 回復(fù) 有任何疑惑可以回復(fù)我~
#2

向遠(yuǎn)之航

樓主這個(gè)就是把方法寫在主類里面。反正main是靜態(tài)方法,只有其它方法也是靜態(tài)的,就可以在main中不通過實(shí)例化對(duì)象進(jìn)行直接調(diào)用。(話說,方法都寫到主方法里面我不是很懂意思,是指都寫成一個(gè)方法么,個(gè)人覺得還是根據(jù)功能不同寫成多個(gè)方法比較好,然后在主方法里面調(diào)用不同功能的方法。)
2019-05-12 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

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

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

進(jìn)入課程

看了n遍視頻終于搞出來了,感覺前面學(xué)的終于沒那么模糊了

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

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

幫助反饋 APP下載

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

公眾號(hào)

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