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

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

剛做出來的,感覺類和對象還是不大會設計。請老師多提提改進的方法。

package?student.carcental;
/**
?*?車類?--抽象類
?*/
public?abstract?class?Car?{
??private?String?carName;???//車的名
??private?int?carNum;???????//車編號
??private?int?carRent;??????//車租金
??
??
???public?String?getCarName()?{
?return?carName;
???}
???
???public?void?setCarName(String?carName)?{
?this.carName?=?carName;
???}
???
???public?int?getCarNum()?{
?return?carNum;
???}
???
???public?void?setCarNum(int?carNum)?{
?this.carNum?=?carNum;
???}
???
???public?int?getCarRent()?{
?return?carRent;
???}
???
???public?void?setCarRent(int?carRent)?{
?this.carRent?=?carRent;
???}
??
}
package?student.carcental;
/**
?*?貨車類
?*/
public?class?Truck?extends?Car?{
private?int?cargoNum;?//載貨量
????
public?Truck(String?carName,int?carRent,int?cargoNum){????//構造方法
this.setCarName(carName);
this.setCarRent(carRent);
this.setCargoNum(cargoNum);
}
public?int?getCargoNum()?{
return?cargoNum;
}
public?void?setCargoNum(int?cargoNum)?{
this.cargoNum?=?cargoNum;
}
}


package?student.carcental;
/**
?*?客車類
?*/
public?class?Passengercar?extends?Car?{
???private?int?capacity;?//載客量
???
???public?Passengercar(String?carName,int?carRent,int?capacity){?
??this.setCarName(carName);
??this.setCarRent(carRent);
??this.setCapacity(capacity);
???}
???public?int?getCapacity()?{
?return?capacity;
???}
???public?void?setCapacity(int?capacity)?{
?this.capacity?=?capacity;
???}??
???
???
???
???
???
}


package?student.carcental;
/**
?*?皮卡類
?*/
public?class?Pickup?extends?Car?{
???private?int?capacity;?//載客量
???private?int?cargoNum;?//載貨量
???
???public?Pickup(String?carName,int?carRent,int?capacity,int?cargoNum){
??this.setCarName(carName);
??this.setCarRent(carRent);
??this.setCargoNum(cargoNum);
??this.setCapacity(capacity);
???}
???
???public?int?getCapacity()?{
return?capacity;
???}
???
???public?void?setCapacity(int?capacity)?{
?this.capacity?=?capacity;
???}
???
???public?int?getCargoNum()?{
?return?cargoNum;
???}
???
???public?void?setCargoNum(int?cargoNum)?{
?this.cargoNum?=?cargoNum;
???}
???
???
}


package?student.carcental;
import?java.util.Arrays;
/**
?*?車輛管理類?增刪查存儲
?*??1。貨車???2.客車?3.皮卡?
?*/
public?class?CarManager?{
???private?Car[]?carSave?=?new?Car[3];??//數(shù)組對象
???private?int?count=0;?//存儲數(shù)據(jù)數(shù)
???
???public?static?Car?getInstance(int?carNum,String?carName,int?carRent,int...loadBearing){???//初始化類
??if(carNum==1){
??return?new?Truck(carName,carRent,loadBearing[0]);
??}else?if(carNum==2){
??return?new?Passengercar(carName,carRent,loadBearing[0]);
??}else?if(carNum==3){
??return?new?Pickup(carName,carRent,loadBearing[0],loadBearing[1]);
??}
??
??return?null;
???}
???
???
???
???
???public?void?addCar(Car?car){??//增加
??//判斷是否超出長度,擴充數(shù)組
??if(count>=carSave.length){
?int?newLen?=?(carSave.length*3)/2?+1;
?carSave?=?Arrays.copyOf(carSave,?newLen);??
??}
??
??if(!searchCar(car.getCarName())){???//判斷是否存在此車型
??//存在時
??System.out.println(car.getCarName()+"此車型已經(jīng)存在");
??}else{
??????//不存在
??car.setCarNum(count+1);
??????carSave[count]?=?car;
??????count++;
??}
???}
???
???public?void?delCar(String?carName){??//刪除
??int?index?=?searchCarNum(carName);
??if(index?!=?-1){
??for?(int?i?=?index;?i?<?count-1;?i++)?{
??
??????????carSave[i]=carSave[i+1];
??????????carSave[i].setCarNum(i+1);?//重置序號
??}
??
??carSave[count-1]=null;
??count--;?
??
??}else{
??System.out.println("車型不存在");
??
??}
??
??
???}
???
???public?void?showCar(){?//顯示
??for?(Car?car:carSave)?{
?if(car!=null){
??System.out.print(car.getCarNum()+";\t");
??System.out.print(car.getCarName()+";\t");
??if?(car?instanceof?Truck)?{
??System.out.print("載貨:"+((Truck)?car).getCargoNum()+"噸;\t\t");
??}
??
??
??if?(car?instanceof?Passengercar)?{
??System.out.print("載人:"+((Passengercar)?car).getCapacity()+"人;\t\t");
??
??}
??
??if?(car?instanceof?Pickup)?{
??System.out.print("載貨:"+((Pickup)?car).getCargoNum()+"噸\\");
??System.out.print("載人:"+((Pickup)?car).getCapacity()+"人;\t");
??
??}?
??
??System.out.print(car.getCarRent()+";\t");
??System.out.println();
?}
??}
??
???}
???
???public?boolean?searchCar(String?carName){?//查詢
??for?(int?i?=?0;?i?<?count;?i++)?{
??if(carName.equals(carSave[i].getCarName())){
??return?false;
??}
??}
??
??return?true;
???}
???
???public?int?searchCarNum(String?carName){??//查詢id
??for?(int?i?=?0;?i?<?count;?i++)?{
??if(carName.equals(carSave[i].getCarName())){
??return?i;
??}
??}
??
??return?-1;
???}
???
???public?Car?returnCar(int?carNum){??//返回車對象
??return?carSave[carNum];
???}
???
???
???
???
}


package?student.carcental;
/**
?*?租車管理接口
?*/
public?interface?IRentalManager?{
????public?void?rentaldata();?//租車數(shù)據(jù)
????public?void?totalList();??//租車統(tǒng)計
????
}


package?student.carcental;
import?java.util.Iterator;
import?java.util.Scanner;
/**
?*?個人租賃類
?*/
public?class?PersonRental?implements?IRentalManager?{
???
public?void?rentaldata(){
System.out.println("歡迎使用答答租車系統(tǒng)");
Scanner?in?=?new?Scanner(System.in);
System.out.println("你是否要租車?1.是?0.否");
int?input?=?in.nextInt();
if?(input==1)?{
System.out.println("可租車輛清單");
System.out.println("序號\t"+"汽車名稱\t"+"容量\t\t"+"租金");
//租車清單
CarManager?cm?=?new?CarManager();
cm?=new?StartData().startData(cm);
???cm.showCar();
???
???
???System.out.println("請輸入租車的數(shù)量:");
???int?rentalNum?=?in.nextInt();
???//租的車輛
???int[]?carArrays?=?new?int[rentalNum];
???for?(int?i?=?0;?i?<?carArrays.length;?i++)?{
System.out.println("請輸入要租"+(i+1)+"號車的序號");
carArrays[i]=in.nextInt()-1;//和存儲的車的序號對其來
}
???
???System.out.println("請輸入天數(shù):");
???int?days?=?in.nextInt();
???
???totalList(carArrays,?days,?cm);??
}else?if(input==0){
System.out.println("感謝使用答答租車系統(tǒng).");
}else{
System.out.println("輸入信息錯誤!");
}
}
public?void?totalList(){
}
public?void?totalList(int[]?ca,int?day,CarManager?cm){
int?total=0;?//總額
String?passengercar="";?//可載人的車
String?truck="";??//可載貨的車
for?(int?i?=?0;?i?<?ca.length;?i++)?{
Car?car?=?cm.returnCar(ca[i]);
total+=car.getCarRent()*day;
if(car?instanceof?Truck){
if(truck.indexOf(car.getCarName()+";")==-1){
truck=truck.concat(car.getCarName()+";");
}
}
if(car?instanceof?Passengercar){
if(passengercar.indexOf(car.getCarName()+";")==-1){
passengercar=passengercar.concat(car.getCarName()+";");
???}
}
if(car?instanceof?Pickup){
if(passengercar.indexOf(car.getCarName()+";")==-1){
passengercar=passengercar.concat(car.getCarName()+";");
???}
if(truck.indexOf(car.getCarName()+";")==-1){
truck=truck.concat(car.getCarName()+";");
???}
}
}
System.out.println("可載人的車輛有:");
System.out.println(passengercar);
System.out.println("可載貨的車輛有:");
System.out.println(truck);
System.out.println("總金額");
System.out.println(total);
}
}


package?student.carcental;
/**
?*?
?*?滴滴租車系統(tǒng)
?*?1.展示所有可租車輛
?*?2.選擇車型、租車量
?*?3.展示租車清單,包含:總金額、總載貨量、總載人量及車型
?*?
?*/
public?class?ShowMain?{
public?static?void?main(String[]?args){
IRentalManager?p?=?new?PersonRental();
p.rentaldata();
}
}


請老師和同學多提意見。剛開始學習java,面向?qū)ο罄鲜怯X得分析起來困難

正在回答

1 回答

package?student.carcental;
/**
?*?貨車類
?*/

public?class?Truck?extends?Car?{
	private?int?cargoNum;?//載貨量
????
	public?Truck(String?carName,int?carRent,int?cargoNum){????//構造方法
		this.setCarName(carName);
		this.setCarRent(carRent);
		this.setCargoNum(cargoNum);
	}
	
	public?int?getCargoNum()?{
		return?cargoNum;
	}

	public?void?setCargoNum(int?cargoNum)?{
		this.cargoNum?=?cargoNum;
	}

}


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

舉報

0/150
提交
取消

剛做出來的,感覺類和對象還是不大會設計。請老師多提提改進的方法。

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

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

幫助反饋 APP下載

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

公眾號

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