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

為了賬號安全,請及時綁定郵箱和手機立即綁定

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

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為總價格,?num_Cargo為總貨物量
	static?int?num_Person;???????????//num_Person為可載總人數(shù)
	public?static?void?main(String[]?args)?{
		if?(askFirst()?==?1)?{		
			Car[]?car?=?{new?PassengerCar("奧迪A4",?500,?4),?new?PassengerCar("馬自達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)?{??????//展示價目表,\t制表符,橫向跳8個空格
		System.out.println("您可租車的類型及其價目表:\n序號\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ù)組記錄所租車輛的編號,tag是該數(shù)組編號
		int?tag?=?0;?		
		for?(int?i?=?1;?i?<=?num;?i++){?????????????//輸入所租車輛序號,更新總價格和載貨量,載人數(shù)等數(shù)據(jù)
		System.out.println("請輸入第"+i+"輛車的序號:");
		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("***租車總價格:"+Price+"元");			
	}
}

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

正在回答

3 回答

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

1 回復 有任何疑惑可以回復我~

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

0 回復 有任何疑惑可以回復我~

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

0 回復 有任何疑惑可以回復我~
#1

慕姐0352535 提問者

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

向遠之航

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

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531103    人
  • 解答問題       6280    個

課程升級!以終為始告別枯燥,在開發(fā)和重構中體會Java面向對象編程的奧妙

進入課程

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

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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