亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

大佬看看 有什么要改的地方

Car頁

package?com;

public?abstract?class?Car?{
????protected?String?name;
????protected?int?price;
????protected?int?style;
????public?Car(int?style,String?name,int?price){
????????this.name=name;
????????this.price=price;
????????this.style=style;
????}
????public?abstract?void?showcars();



Truruck頁

package?com;

public?class?Truck?extends?Car{
????protected?int?weight;
????public?Truck(int?style,String?name,int?price,int?weight){
?????????super(style,name,price);
?????????this.weight=weight;
????}

????@Override
????public?void?showcars()?{
????????????System.out.println(this.name?+?"?"+this.price+"元/天"+"?載貨:"+this.weight+"噸");
????}
}

Bus頁

package?com;

public?class?Bus?extends?Car{
????protected?int?num;
????public?Bus(int?style,String?name,int?price,int?num){
????????super(style,name,price);
????????this.num=num;
????}

????@Override
????public?void?showcars()?{
????????System.out.println(this.name?+?"?"+this.price+"元/天"+"?載人:"+this.num+"人");
????}
}



Pickup頁

package?com;

public?class?Pickup?extends?Car{
????protected?int?weight;
????protected?int?num;
????public?Pickup(int?style,String?name,int?price,int?num,int?weight){
????????super(style,name,price);
????????this.num=num;
????????this.weight=weight;
????}

????@Override
????public?void?showcars()?{
????????System.out.println(this.name?+?"?"+this.price+"元/天"+"?載人:"+this.num+"?載貨:"+this.weight+"噸");
????}
}


main頁

package?com;

import?java.util.Scanner;

public?class?Test?{
????public?static?void?main(String[]?args)?{
????????Scanner?input?=?new?Scanner(System.in);
????????System.out.println("歡迎使用租車系統,請問是否需要租車:1是?0否");
????????int?index?=?input.nextInt();
????????if?(index?==?1)?{
????????????Car[]?cars?=?{new?Bus(1,"奧迪A4",?500,?4),?new?Bus(1,"馬自達6",?400,?4),
????????????????????new?Bus(1,"金龍",?800,?20),new?Pickup(0,"皮卡雪",?450,?4,?2),
????????????????????new?Truck(2,"松花江",?400,?4),?new?Truck(2,"依維柯",?1000,?20)};

????????????System.out.println("您可租車的類型和價目表:");
????????????System.out.println("序號??汽車名稱??租金??容量");
????????????for?(int?i?=?1;?i?<=?cars.length;?i++)?{
????????????????System.out.print(i?+?"?");
????????????????cars[i?-?1].showcars();
????????????}
????????????System.out.println("請輸入需要的數量");
//????????????車輛數量
????????????int?carNum?=?input.nextInt();

//????????????可載人的車
????????????String?bus="";
//????????????載人數量
????????????int?nums=0;

//????????????載貨的車
????????????String?trunk="";
//????????????載貨重量
???????????int?weights=0;
//???????????總價
????????????int?allPrice=0;
????????????for?(int?i?=?1;?i?<=?carNum;?i++)?{
????????????????System.out.println("請輸入第"?+?i?+?"輛車的序號");
????????????????//車輛序號?carIndex-1
????????????????int?carIndex?=?input.nextInt();
????????????????if(cars[carIndex-1].style==0){
//????????????????????載人和載物的車
????????????????????nums+=((Pickup)?cars[carIndex-1]).num;
????????????????????weights+=((Pickup)?cars[carIndex-1]).weight;
????????????????????bus+="?"+cars[carIndex-1].name;
????????????????}else?if(cars[carIndex-1].style==1){
//????????????????????載人的車
????????????????????bus+="?"+cars[carIndex-1].name;
????????????????????nums+=((Bus)?cars[carIndex-1]).num;
????????????????}else?if(cars[carIndex-1].style==2){
//????????????????????載物的車
????????????????????trunk+="?"+?cars[carIndex-1].name;
????????????????????weights+=((Truck)?cars[carIndex-1]).weight;
????????????????}
????????????????allPrice+=cars[carIndex-1].price;
????????????}
????????????System.out.println("請輸入租車天數");
//????????????租車天數
????????????int?carDay?=?input.nextInt();
????????????allPrice*=carDay;
????????????System.out.println("您的賬單:");
????????????System.out.println("***可載人的車有:");
????????????System.out.println(bus+"?共載:"+nums+"人");
????????????System.out.println("***可載貨的車有:");
????????????System.out.println(trunk+"?共載:"+weights+"噸");
????????????System.out.println("***租車價格:"?+?allPrice+"元");
????????}
????}
}


正在回答

1 回答

問題就在Car頁,后面少了個大括號啊。是你沒復制過來?

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

舉報

0/150
提交
取消

大佬看看 有什么要改的地方

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

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號