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

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

我的作業(yè)提交

//基類
package?car_rent;

public?abstract?class?Car?{
????String?name;
????int?person;
????double?price;
????double?weight;
????//客車
????public?Car(String?name,int?person,double?price){
????????this.name?=?name;
????????this.person?=?person;
????????this.price?=?price;
????}
????//貨車
????public?Car(String?name,double?weight,double?price){
????????this.name?=?name;
????????this.weight?=?weight;
????????this.price?=?price;
????}
????//皮卡
????public?Car(String?name,int?person,?double?weight,double?price){
????????this.name?=?name;
????????this.weight?=?weight;
????????this.price?=?price;
????????this.person?=?person;
????}
????public?void?showInfo(int?num,int?days){
????????double?totalAmount;
????????totalAmount?=?num?*?days?*?price;
????????System.out.println("您選擇的車是:"+name+"價(jià)格是:"+price+"/天,數(shù)量為"+num+"輛,天數(shù)為"+days+"天,總計(jì)"+totalAmount+"元");
????}
????public?abstract?void?show();
}

//客車類
public?class?PassengerCar?extends?Car?{
????public?PassengerCar(String?name,int?person,double?price){
????????super(name,person,price);
????}
????public?void?show(){
????????System.out.println(name+"?"+price+"/天,可以載人數(shù):"+person);
????}
}
//卡車類
public?class?Truk?extends?Car?{
????Truk(String?name,double?weight,double?price){
????????super(name,weight,price);
????}

????public?void?show(){
????????System.out.println(name+"?"+price+"/天,載重量為:"+weight+"噸");
????}
}
//皮卡類
public?class?Pickup?extends?Car?{
????Pickup(String?name,int?person,?double?weight,double?price){

????????super(name,person,weight,price);
????}

????public?void?show(){
????????System.out.println(name+"?"+price+"/天,可載人數(shù)"+person+"?載重量為:"+weight+"噸");
????}
}
//入口
package?car_rent;
import?java.util.Scanner;

public?class?Index?{
????public?static?void?main(String[]?args){
????????Car[]?cars?=?{
??????????new?PassengerCar("馬自達(dá)",6,150),
??????????new?Pickup("皮卡雪",4,3,300),
??????????new?Truk("東風(fēng)重卡",20,350)
????????};
????????System.out.println("歡迎使用XXX租車系統(tǒng)");
????????System.out.println("是否租車:1-是??0否");
????????Scanner?input1?=?new?Scanner(System.in);
????????int?xz?=?input1.nextInt();
????????if(xz?==?1){
????????????System.out.println("請(qǐng)選擇租車類型:");
????????????for?(int?i=1;i<=?cars.length;i++){
????????????????System.out.print("編號(hào):"+i+"?");
????????????????cars[i-1].show();
????????????}
????????????System.out.println("請(qǐng)選擇編號(hào):");
????????????Scanner?input2?=?new?Scanner(System.in);
????????????int?carIndex?=?input2.nextInt();
????????????if(carIndex?<=?0?||?carIndex?>?cars.length){
????????????????System.out.println("輸入錯(cuò)誤,退出系統(tǒng)");
????????????????System.exit(0);
????????????}
????????????System.out.println("請(qǐng)選擇數(shù)量:");
????????????Scanner?input4?=?new?Scanner(System.in);
????????????int?num?=?input4.nextInt();
????????????if(num?<=?0?){
????????????????System.out.println("輸入錯(cuò)誤,退出系統(tǒng)");
????????????????System.exit(0);
????????????}
????????????System.out.println("請(qǐng)選擇租車天數(shù):");
????????????Scanner?input3?=?new?Scanner(System.in);
????????????int?days?=?input3.nextInt();
????????????if(days?<=?0){
????????????????System.out.println("輸入錯(cuò)誤,退出系統(tǒng)");
????????????????System.exit(0);
????????????}
????????????for?(int?i=1;i<=?cars.length;i++){
????????????????if(carIndex?==?i){
????????????????????cars[i-1].showInfo(num,days);
????????????????????break;
????????????????}
????????????}



????????}else?{
????????????System.out.println("退出系統(tǒng)");
????????????System.exit(0);
????????}
????}
}


正在回答

4 回答

沒看懂那個(gè)exit(0)方法是哪來的

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

學(xué)習(xí)了

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

大佬寫的好。學(xué)習(xí)了。

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

繼承還可以優(yōu)化,父類的重載有些繁瑣了,可以簡(jiǎn)化。還有就是,如果記錄人數(shù),最好用personNum之類的命名方式,person更偏向于類,而不是一個(gè)變量。

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

舉報(bào)

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

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

進(jìn)入課程

我的作業(yè)提交

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

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

幫助反饋 APP下載

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

公眾號(hào)

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