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

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

有更簡化的方法嗎

//父類
public?abstract?class?Car?{

????//使用封裝概念,設(shè)置屬性
????private?String?name;
????private?double?rent;
????private?int?Manned;
????private?double?Cargo;
????
????//使用set、get方法讀寫屬性
????public?int?getManned()?{
????????return?Manned;
????}
????public?void?setManned(int?manned)?{
????????Manned?=?manned;
????}
????public?double?getCargo()?{
????????return?Cargo;
????}
????public?void?setCargo(double?cargo)?{
????????Cargo?=?cargo;
????}
????public?double?getRent()?{
????????return?rent;
????}
????public?void?setRent(double?rent)?{
????????this.rent?=?rent;
????}
????public?String?getName()?{
????????return?name;
????}
????public?void?setName(String?name)?{
????????this.name?=?name;
????}
????//繼承父類
public?class?PassengerCar?extends?Car?{
????????

????//使用this方法
????public?PassengerCar(String?name,?double?rent,int?manned)?{
????????
????????this.setName(name);
????????this.setRent(rent);
????????this.setManned(manned);
????}

????public?String?toString()?{
????????return?this.getName()+"\t"+this.getRent()+"/天"+"\t"+"可乘坐:"+this.getManned()+"人";
????}
????
????//繼承父類
public?class?CargoCapacity?extends?Car?{
????

????
????
????public?CargoCapacity(String?name,?double?rent,double?Cargo)?{
????????
????????this.setName(name);
????????this.setRent(rent);
????????this.setCargo(Cargo);
????}

????public?String?toString()?{
????????return?this.getName()+"\t"+this.getRent()+"/天"+"\t"+"可載貨:"+this.getCargo()+"噸";
????}
????//繼承父類
public?class?Pickup?extends?Car?{
????
????public?Pickup(String?name,?double?rent,?int?manned,double?cargo)?{
????
????????this.setName(name);
????????this.setRent(rent);
????????this.setManned(manned);
????????this.setCargo(cargo);
????}
????
????
????public?String?toString()?{
????????
????????return?this.getName()+"\t"+this.getRent()+"/天"+"\t"+"可乘坐"+this.getManned()+"人,"+"載貨"+this.getCargo()+"噸";
????}
????
????//測試類
????public?class?test?{

????public?static?void?main(String[]?args)?{
????????//?TODO?Auto-generated?method?stub

????????System.out.println("歡迎使用答答租車系統(tǒng)");
????????System.out.println("您是否要租車:?1是?0否");
????????Car[]?au?=?{new?PassengerCar("奧迪A8L",800,1),new?PassengerCar("大金龍",1000,1),
????????????????new?CargoCapacity("福田歐曼",1200,5),new?CargoCapacity("一汽解放",950,40),
????????????????new?Pickup("皮卡",1500,1,2)};
????????Scanner?sc?=?new?Scanner(System.in);
????????String?input?=?sc.nextLine();
????????if(input.equals("1"))?{
????????????System.out.println("您可租車的類型及其價(jià)目表");
????????????System.out.println("序號(hào)\t汽車名稱\t租金\t\t容量");????????
????????????for(int?i?=?0;?i<au.length;?i++)?{????????????????????
????????????????System.out.println((i+1)+"\t"+au[i]);
????????????????
????????????}
????????}else?if(input?!=?"1")?{
????????????System.out.println("感謝您使用答答租車系統(tǒng),祝您生活愉快?。?);
????????}
????????System.out.println("請您輸入需要租賃汽車的數(shù)量:");
????????int?carcount?=?sc.nextInt();
????????
????????//更新車輛數(shù)組
????????Car[]?newcar=new?Car[carcount];

????????double?bills=0;
????????int?zren=0;
????????double?zhuo=0;
????????for(int?i=0;i<carcount;i++)?{
????????????????????????????????????
????????????????System.out.println("請您輸入第"+(i+1)+"輛車的序號(hào):");
????????????????int?carnum=sc.nextInt();
????????????????newcar[i]?=?au[carnum-1];
????????????
????????}????
????????System.out.println("請你輸入租賃的天數(shù):");
????????int?day=sc.nextInt();
????????//計(jì)算租金
????????for(int?i=0;i<carcount;i++)?{
?????????????bills=bills+newcar[i].getRent()*day;

????????}
????????//輸出賬單
????????System.out.println("你的賬單");
????????//列出所選乘用車并計(jì)算總的載人數(shù)
????????System.out.println("*****可載人的車有");
????????for(int?i=0;i<carcount;i++)?{
????????????if(newcar[i].getManned()?!=?0)?{

????????????????zren?+=?newcar[i].getManned();
????????????????System.out.println(newcar[i]);
????????????}
????????????????????
????????}
????????
????????System.out.println("*****可載貨的車有");
????????
????????for(int?i?=?0?;i<carcount;i++)?{
????????????if(newcar[i].getCargo()?!=?0)?{
????????????????
????????????????zhuo?+=newcar[i].getCargo();
????????????????System.out.println(newcar[i]);
????????????}
????????}
????????
????????System.out.println("共可載客"+zren+"人");

????????System.out.println("共可載貨"+zhuo+"噸");

????????System.out.println("請付租金"+bills+"元");
????}


正在回答

5 回答

你這個(gè)子類toString方法里面沒必要用this吧,我記得this不是要靜態(tài)類或者變量才可以調(diào)用,難道我記錯(cuò)了嗎?

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

public static void main(String[] args) {

// TODO Auto-generated method stub

//初始化,輸入擁有的車的信息

Vehicle[] vehs =new Vehicle[5];

vehs[0] = new Truck("mo1", 100, 10);

vehs[1] = new Truck("mo2", 200, 20);

vehs[2] = new Truck("mo3", 300, 30);

vehs[3] = new Car("car1", 1000, 10);

vehs[4] = new Car("car2", 2000, 20);


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

請問怎么才能像你那樣把代碼分行顯示出來?

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

有個(gè)問題,如果剛開始 “您是否要租車:?1是?0否 ”后面用戶輸入的數(shù)字不等于1的話,程序還會(huì)繼續(xù)執(zhí)行下去。

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

不錯(cuò)哦

0 回復(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)