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

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

我的作業(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+"價格是:"+price+"/天,數(shù)量為"+num+"輛,天數(shù)為"+days+"天,總計"+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("馬自達",6,150),
??????????new?Pickup("皮卡雪",4,3,300),
??????????new?Truk("東風重卡",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("請選擇租車類型:");
????????????for?(int?i=1;i<=?cars.length;i++){
????????????????System.out.print("編號:"+i+"?");
????????????????cars[i-1].show();
????????????}
????????????System.out.println("請選擇編號:");
????????????Scanner?input2?=?new?Scanner(System.in);
????????????int?carIndex?=?input2.nextInt();
????????????if(carIndex?<=?0?||?carIndex?>?cars.length){
????????????????System.out.println("輸入錯誤,退出系統(tǒng)");
????????????????System.exit(0);
????????????}
????????????System.out.println("請選擇數(shù)量:");
????????????Scanner?input4?=?new?Scanner(System.in);
????????????int?num?=?input4.nextInt();
????????????if(num?<=?0?){
????????????????System.out.println("輸入錯誤,退出系統(tǒng)");
????????????????System.exit(0);
????????????}
????????????System.out.println("請選擇租車天數(shù):");
????????????Scanner?input3?=?new?Scanner(System.in);
????????????int?days?=?input3.nextInt();
????????????if(days?<=?0){
????????????????System.out.println("輸入錯誤,退出系統(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 回答

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

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

學習了

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

大佬寫的好。學習了。

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

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

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

舉報

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

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

進入課程

我的作業(yè)提交

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

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

幫助反饋 APP下載

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

公眾號

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