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

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

請大家多多指教

public class Car {

private String name;

private double price;

private int guest;

double goods;

public Car(String name,double price,int guest,double goods) {

this.name=name;

this.price=price;

this.guest=guest;

this.goods=goods;

}

public String getname() {

return name;

}

public double getprice() {

return price;

}

public int getguest() {

return guest;

}

public double getgoods() {

return goods;

}

}

import java.util.Scanner;

public class Initail {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner sc=new Scanner(System.in);

double price=0;

double guest=0;

double goods=0;

int d=0;

Car[] CarList= {

new Car("奧迪",2000,5,0),

new Car("寶馬",2500,5,0),

new Car("五菱宏光",800,12,0),

new Car("法拉利",8000,2,0),

new Car("小卡車",2000,0,5),

new Car("大卡車",5000,0,15),

new Car("皮卡",1000,2,2),

};

System.out.println("歡迎來到答答租車!");

System.out.println("租車請輸入1,退出請輸入任意鍵");

String scanf=sc.next().toString();

if(scanf.equals("1")) {

System.out.println("以下是車輛列表:");

for(int i=0;i<CarList.length;i++) {

System.out.println("序列號:"+i+"\t"+CarList[i].getname()+"\t"+CarList[i].getprice()+"\t"+CarList[i].getguest()+"\t"+CarList[i].getgoods());

}

System.out.println("請輸入需要的車輛的序列號并使用逗號隔開:");

String str=sc.next().toString();

String[] arr=str.split(",");

if(arr.length>0){

for(int i=0;i<arr.length;i++) {

String b=arr[i];

int c=0;

if(b!=null || b.length() != 0) {

for(int j=0;j<b.length();j++) {

if(b.charAt(j)<'0'||b.charAt(j)>'9')

{

c++;

break;

}

}

if(c==0) {

int a=Integer.parseInt(arr[i]);

if(a<CarList.length) {

price+=CarList[Integer.parseInt(arr[i])].getprice();

guest+=CarList[Integer.parseInt(arr[i])].getguest();

goods+=CarList[Integer.parseInt(arr[i])].getgoods();

}else {

d++;

break;

}

}

}else {

d++;

}

}

if(d==0) {

System.out.println("以下是您租車的列表:");

for(int i=0;i<arr.length;i++) {

int b=Integer.parseInt(arr[i]);

System.out.println("序列號:"+i+"\t"+CarList[i].getname()+"\t"+CarList[i].getprice()+"\t"+CarList[i].getguest()+"\t"+CarList[i].getgoods());

}

System.out.println("您的訂單總價為:"+price+"\t"+"總載客量為:"+guest+"\t"+"總載貨量為:"+goods);

System.out.println("歡迎再次光臨!");

}else {

System.out.println("輸入的參數有誤!");

}

}else {

System.out.println("輸入的參數有誤!");

}

}else {

System.out.println("歡迎再次光臨!");

}

}

}


正在回答

1 回答

有什么毛病嗎?

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

舉報

0/150
提交
取消

請大家多多指教

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

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

幫助反饋 APP下載

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

公眾號

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