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

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

租車系統,小白一個,,過程有點亂,望高手們指點指點。

import java.util.Scanner;

public class Car?

{

Scanner in=new Scanner(System.in);

int q,b,d,l,a,o,k,cs=0,p=0;//cs表示載人的累加值。p表示可載貨車輛的累加值。

double s,count=0,ds=0;//count表示租金的累加值。ds表示噸位的累加值。

public Ddffdsf(int newA) ?//構造方法初始化a值

? {

a=newA;

?}

?public void cl()

?{

if(a==1) ?//當a為1時輸出以下表格并調用本類中的cc方法

? { ? ??

System.out.println("您可租車的類型及其價目表:");

System.out.println("序號 ? ? ?汽車名稱 ? ? ? ? ? ? ? 租金 ? ? ? ? ? ? ? ? ? ? ? ? ? 容量");

? ?System.out.println(" 1 ? ? 奧迪A8 ? ? 10000元/天 ? ? ? ? ? ?載人:2人");

? ?System.out.println(" 2 ? ? 蘭博基尼 ? ? ? ?12220元/天 ? ? ? ? ? ?載人:2人");

? ?System.out.println(" 3 ? ? 奔馳S600 ? ?9000元/天 ? ? ? ? ? ?載人:5人");

? ?System.out.println(" 4 ? ? 寶馬M8 ? ? ?9999元/天 ? ? ? ? ? ?載人:4人");

? ?System.out.println(" 5 ? ? 皮卡 ? ? ? ? ? ? ? ? ?888元/天 ? ? ? ? ? ? ? 載人:4人 ? 可載貨:2噸");

? ?System.out.println(" 6 ? ? 林肯加長 ? ? ? ?22222元/天 ? ? ? ? ? ?載人:12人");

? ?System.out.println(" 7 ? ? 法拉利 ? ? ? ? ? ?77777元/天 ? ? ? ? ? ?載人: 2人");

? ?System.out.println(" 8 ? ? 一汽卡車 ? ? ? ? ? 777元/天 ? ? ? ? ? ? 載人: 2人 ?可載貨:10噸");

? ?cc();

? }

else ? ?//當輸入的數不是1時,輸出"歡迎下次光臨!"。

? {

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

? ? ? ? ? ?}

?}

? public void cc()

? ? ? {

? System.out.print("請輸入您要租汽車的數量:");

? ? ? ? b=in.nextInt(); ? ? ? //讀取一個整數

? ? ?if(b>0) ? ? ? ? ? ? ?//b如果大于0

? ? ? ? ?{

? ? this.b=b; ? ? ? ? //把讀取的b賦值給this.b

? ? for(int i=0;i<b;i++) ? ? //使用for循環讓用戶輸入要選擇車輛的序號

? {

? System.out.print("請輸入第"+(i+1)+"輛汽車的序號:");

? ? ? ? q=in.nextInt(); ? //讀取用戶輸入的序號

?if(q<=0|q>8) ? ? ?//如果用戶輸入的序號不在系統規定的范圍內,則運行大括號里面的代碼

? ? { ?

? ? ? ? while(q<=0|q>8) ? //則使用while循環 以提示用戶重新輸入,只有重新輸入的序號在規定的范圍內,循環才會結束。

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //這樣避免輸入錯誤后又要重新運行系統

? ? ? ? { ? ? ? ? ? ? ? ? ?

? ? ? ? System.out.println("您輸入的序號錯誤,請重新輸入。");

? ? ? ? System.out.print("請輸入第"+(i+1)+"輛汽車的序號:");

? ? ? ? ? ?q=in.nextInt(); ?

? ? ? ? } ? ? ? ? ? ? ? ? ? ?//如果重新輸入的序號在規定的范圍內,則系統會進行判斷,進行配對和運算

? ? ? ? if(q==1){d=2;s=10000;count=count+s;cs=cs+d;}

? ? ? ? if(q==2){d=2;s=12220;count=count+s;cs=cs+d;}

? ? ? ? if(q==3){d=5;s=9000;count=count+s;cs=cs+d;}

? ? ? ? if(q==4){d=4;s=9999;count=count+s;cs=cs+d;}?

? ? ? ? if(q==5){d=4;k=2;s=888;count=count+s;cs=cs+d;ds=ds+k;p++;}?

? ? ? ? if(q==6){d=12;s=22222;count=count+s;cs=cs+d;}?

? ? ? ? if(q==7){d=2;s=77777;count=count+s;cs=cs+d;}

? ? ? ? if(q==8){d=2;k=10;s=777;count=count+s;cs=cs+d;ds=ds+k;p++;}

? ? ? ? ? ? ?}?

? ? ? ? else ? ? ? ? ? ? ? ? //如果用戶輸入序號在系統規定的范圍內,則運行大括號里面的代碼,進行累加運算

? ? ? ? ? ? ? ? {

? ? ? ? if(q==1){d=2;s=10000;count=count+s;cs=cs+d;}

? ? ? ? if(q==2){d=2;s=12220;count=count+s;cs=cs+d;}

? ? ? ? if(q==3){d=5;s=9000;count=count+s;cs=cs+d;}

? ? ? ? if(q==4){d=4;s=9999;count=count+s;cs=cs+d;}?

? ? ? ? if(q==5){d=4;k=2;s=888;count=count+s;cs=cs+d;ds=ds+k;p++;}?

? ? ? ? if(q==6){d=12;s=22222;count=count+s;cs=cs+d;}?

? ? ? ? if(q==7){d=2;s=77777;count=count+s;cs=cs+d;}

? ? ? ? if(q==8){d=2;k=10;s=777;count=count+s;cs=cs+d;ds=ds+k;p++;} ? ? ? ??

? ? ? ? ? ? ? ? } ? ? ?

? ? ? ? ? ?} ? ? ? ? ? ? ? ??

? ? System.out.print("請輸入租車天數:");

? ? ? ? ? ?l=in.nextInt(); ??

? ? ? ? ? ?if(l>0) ? ? ? ? ? ? //如果讀取的天數大于0,則運行大括號里面的代碼

? ? {

? ? ? ? ? this.l=l; ? ?//將讀取到的天數l賦值給this.l

? ? ? ? if(ds>0) ? ? ?//判斷噸位的累加值是否大于0,如果大于0則最終輸出會帶有噸位和提示可載貨的車輛有多少

? ? ? ? ? {

? ?System.out.println("您需支付"+count*l+"元"+" ? "+"總共可載客人數為:"+cs+"人"+"可載貨的車輛有:"+p+"輛"+" ? "+"其中總可載貨"+ds+"噸");?

? ?System.out.println("歡迎您下次光臨!");

? ? ? ? ? }?

? ? ? ? else //如果噸位的累加值小于或等于0,則最終輸出就只有總載人數和價格

? ?{

? ? System.out.println("您需支付"+count*l+"元"+" ? "+"總共可載客人數為:"+cs+"人");

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

? ?}

? ? ?}

? ? ? ? ? else ? //這個else代表如果用戶輸入租車的天數小于0,就也會進入一個while循環,提示用戶重新輸入租車天數。

? ? ? ? ? ? ? ? ?//這樣也可以避免到輸入天數的時候,輸入錯誤時,不會導致又要再次運行系統重新開始。

? ? ? ? ? {

? ? ? ? ? while(l<=0)

? ? ? ? ? ? ? {

? ? ? ? ? System.out.println("您輸入租車天數的數據有誤,請重新輸入。");?

? ? ? ? ? ? l=in.nextInt();

? ? ? ? ? }?

? ? ? ? ? this.l=l; ?//當重新輸入的租車天數不滿足while循環的條件時,就會把l值賦值給this.l

? ? ? ? ? if(ds>0) ??

? {

? ?System.out.println("您需支付"+count*l+"元"+" ? "+"總共可載客人數為:"+cs+"人"+"可載貨的車輛有:"+p+"輛"+" ? "+"其中總可載貨:"+ds+"噸");?

? ?System.out.println("歡迎您下次光臨!");

? }

? ? ? ? ? else

? ? ? ? {

? ? ? ? ? ?System.out.println("您需支付"+count*l+"元"+" ? "+"總共可載客人數為:"+cs+"人");

? ? ? ?System.out.println("歡迎您下次光臨!"); ?

? ? ? ? } ?

? ? ? ? ? }

? ? ? ? ?}

? ? ?else ? ? ?//表示如果剛開始輸入的數量b小于等于0

? ? ? ? ? //再次利用while循環

? ? ? {

? ? ?while(b<=0)

? ? ?{

? ? ?System.out.println("您輸入租汽車的數量數據有誤,請重新輸入。");

? ? ?b=in.nextInt();

? ? ?}

? ? ?this.b=b; //因為重新輸入的數量b大于0,所以就得從獲取序號這步繼續運行下去

? ? ?for(int i=0;i<b;i++)

? ? ? ? ? ? ? ? ? ?{

? System.out.print("請輸入第"+(i+1)+"輛汽車的序號:");

? ? ? ? q=in.nextInt();

? ? ? ? if(q<=0|q>8) ??

? ? ? ? ? ? { ?

? ? ? ? while(q<=0|q>8)//當重新輸入的數量正確時,接下來序號輸入錯誤,那么就用while循環提示用戶修改,直到正確才執行下一步

? ? ? ? ? {

? ? ? ? System.out.println("您輸入的序號錯誤,請重新輸入。");

? ? ? ? System.out.print("請輸入第"+(i+1)+"輛汽車的序號:");

? ? ? ? q=in.nextInt();

? ? ? }

? ? ? ? if(q==1){d=2;s=10000;count=count+s;cs=cs+d;}

? ? ? ? if(q==2){d=2;s=12220;count=count+s;cs=cs+d;}

? ? ? ? if(q==3){d=5;s=9000;count=count+s;cs=cs+d;}

? ? ? ? if(q==4){d=4;s=9999;count=count+s;cs=cs+d;}?

? ? ? ? if(q==5){d=4;k=2;s=888;count=count+s;cs=cs+d;ds=ds+k;p++;}?

? ? ? ? if(q==6){d=12;s=22222;count=count+s;cs=cs+d;}?

? ? ? ? if(q==7){d=2;s=77777;count=count+s;cs=cs+d;}

? ? ? ? if(q==8){d=2;k=10;s=777;count=count+s;cs=cs+d;ds=ds+k;p++;}

? ? ? ? ? ? }?

? ? ? ? else ? //重新輸入數量b正確后,輸入序號也在系統的范圍內,則執行這一步

? ? ? ? ? ? ? ? {

? ? ? ? if(q==1){d=2;s=10000;count=count+s;cs=cs+d;}

? ? ? ? if(q==2){d=2;s=12220;count=count+s;cs=cs+d;}

? ? ? ? if(q==3){d=5;s=9000;count=count+s;cs=cs+d;}

? ? ? ? if(q==4){d=4;s=9999;count=count+s;cs=cs+d;}?

? ? ? ? if(q==5){d=4;k=2;s=888;count=count+s;cs=cs+d;ds=ds+k;p++;}?

? ? ? ? if(q==6){d=12;s=22222;count=count+s;cs=cs+d;}?

? ? ? ? if(q==7){d=2;s=77777;count=count+s;cs=cs+d;}

? ? ? ? if(q==8){d=2;k=10;s=777;count=count+s;cs=cs+d;ds=ds+k;p++;}

? ? ? ? ? ? ? ? }

? ? ? ?System.out.print("請輸入租車天數:");

? ? ? ? ? ?l=in.nextInt();

? ? ? ? ? ?if(l>0)//重新輸入數量b正確后,輸入序號也在系統的范圍內,接下來的租車天數輸入的值也正確,則執行這一步

? ? ? ? ? ? ? {

? ? ? ? ? this.l=l;

? ? ? ? ? if(ds>0)

? ? ? ? ? {

? ?System.out.println("您需支付"+count*l+"元"+" ? "+"總共可載客人數為:"+cs+"人"+" ?"+"其中可載貨的車輛有:"+p+"輛"+" ? "+"總可載貨:"+ds+"噸");?

? ?System.out.println("歡迎您下次光臨!");

? ? ? ? ? }else?

? ? ? ? ? ? ?{

? System.out.println("您需支付"+count*l+"元"+" ? "+"總共可載客人數為:"+cs+"人");

System.out.println("歡迎您下次光臨!");?

? ? ? ? ? ? ?}?

? ? ? ? ? ? ? ? ? ? }

else //重新輸入數量b正確后,輸入序號也在系統的范圍內,接下來的租車天數輸入的值不正確,則執行這一步

?//利用while循環提示用戶進行修改

{

? ?while(l<=0)

? ? ? ? {

System.out.println("您輸入租車天數的數據有誤,請重新輸入。");?

l=in.nextInt();

? ? ? ? }?

? this.l=l;

? if(ds>0)

? ? ? ?{

? ? ? System.out.println("您需支付"+count*l+"元"+" ? "+"總共可載客人數為:"+cs+"人"+" ?"+"其中可載貨的車輛有:"+p+"輛"+" ? "+"總可載貨:"+ds+"噸");

? ? ? System.out.println("歡迎您下次光臨!");

? ? ? ? ? ? ? ?}

? else?

? ? ? ? ? {

? ? System.out.println("您需支付"+count*l+"元"+" ? "+"總共可載客人數為:"+cs+"人");

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

? ? ? }

? }

? ? ? ? } ? ? ? ?

?} ? ? ??

? ? ? }

}?

**********************************************************

//創建第二個類,名稱為Main,在main函數里調用Car中的cl方法

public class Main {

public static void main(String[] args) {

int a;

Scanner in=new Scanner(System.in);

System.out.println("歡迎光臨飛騰租車!");

System.out.println("是否需要租車:1是 0否");

? a=in.nextInt();

? Car b=new Car(a); ? ? ??

? ? ? ?b.cl(); ? ?

}

}


正在回答

1 回答

其實我也不懂。。就亂改,2個地方

?Car b= new Car();

? ? ? b.cl(a);?

還有就是

public void cl(int i)

?{

if(i==1)

不曉得是不是你想要的效果

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

舉報

0/150
提交
取消

租車系統,小白一個,,過程有點亂,望高手們指點指點。

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

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

幫助反饋 APP下載

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

公眾號

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