2013-10-15 87 views
-3

我爲我的CSE 20課程做了第一個項目,我必須編寫一個簡單的租賃汽車系統。我一開始就陷入困境。我需要問車子,天數,然後你是否是俱樂部會員。如果你的代碼不需要繼續並輸出它的總數。但是如果你是一個俱樂部會員,它必須提出另一個關於高管包的問題,​​那麼這就增加了總輸出的另一條線。我不知道如何編寫代碼才能完全運行。任何幫助,將不勝感激。要求變量只有如果爲真

import java.util.Scanner; 

public abstract class Bobcar1 { 

public static void main(String[] args) { 
    // TODO Auto-generated method stub 

    Scanner blah = new Scanner(System.in); 
    System.out.println("Available cars: 1 for Econobox, 2 for Compact, 3 for Standard"); 
    System.out.print("Please choose the rental car: "); 
    int car; 
    car = blah.nextInt(); 
    System.out.print("Please enter the number of rental days: "); 
    int day; 
    day = blah.nextInt(); 
    System.out.print("Club member?: 1 for yes, 0 for no: "); 
    int re; 
    re = blah.nextInt(); 
    if (re == 1) 
     System.out.print("Platinum Executive Package?: 1 for yes, 0 for no: "); 
    int pack; 
    pack = blah.nextInt(); 
    if (re == 0) then what do i code here to get the program to run through completely? 

    if (car == 1) { 
      int car1; 
      car1 = (25 * day); 

        System.out.println("Base: " + day + " day(s) for a Econobox @ $25 per day:  " + "+$" + car1); 
        if (pack == 0 && re == 0)  { 
        System.out.println(); 
        System.out.println("Total Estimate for Rental:     " + " $" + car1); 
        } 
        if (re == 1 && pack == 0)  { 
          int re1; 
          re1 = (day/5)*25; 
        System.out.println("Club Member Discount:     " + "-$" + re1); 
          int total1r; 
          total1r = car1 - re1; 
        System.out.println(); 
        System.out.println("Total Estimate for Rental:     " + " $" + total1r); 
        } 
        if (pack == 1 && re == 1)  { 
          int pack1; 
          pack1 = (int) (car1*.20); 
        System.out.println("Platinum Executive Package:     " + "+$" + pack1);  
          int re1; 
          re1 = (day/5)*25; 
        System.out.println("Club Member Discount:     " + "-$" + re1); 
          int total1; 
          total1 = car1 + pack1 - re1; 
          System.out.println("Total Estimate for Rental:     " + " $" + total1); 
        } 
    } 
    if (car == 2) { 
      int car1; 
      car1 = (55 * day); 

        System.out.println("Base: " + day + " day(s) for a Compact @ $55 per day: " + "+$" + car1); 
        if (pack == 0 && re == 0)  { 
        System.out.println(); 
        System.out.println("Total Estimate for Rental:     " + " $" + car1); 
        } 
        if (re == 1 && pack == 0)  { 
          int re1; 
          re1 = (day/5)*55; 
        System.out.println("Club Member Discountt:     " + "-$" + re1); 
          int total1r; 
          total1r = car1 - re1; 
        System.out.println(); 
        System.out.println("Total Estimate for Rental:     " + " $" + total1r); 
        } 
        if (pack == 1 && re == 1)  { 
          int pack1; 
          pack1 = (int) (car1* .20); 
        System.out.println("Platinum Executive Package:     " + "+$" + pack1);  
          int re1; 
          re1 = (day/5)*55; 
        System.out.println("Club Member Discount:     " + "-$" + re1); 
          int total1; 
          total1 = car1 + pack1 - re1; 
          System.out.println("Total Estimate for Rental:     " + " $" + total1); 
        } 
    } 
    if (car == 3) { 
      int car1; 
      car1 = (100 * day); 

        System.out.println("Base: " + day + " day(s) for a Standard @ $100 per day:  " + "+$" + car1); 
        if (pack == 0 && re == 0)  { 
        System.out.println(); 
        System.out.println("Total Estimate for Rental:     " + " $" + car1); 
        } 
        if (re == 1 && pack == 0)  { 
          int re1; 
          re1 = (day/5)*100; 
        System.out.println("Return Customer Discount:     " + "-$" + re1); 
          int total1r; 
          total1r = car1 - re1; 
        System.out.println(); 
        System.out.println("Total Estimate for Rental:     " + " $" + total1r); 
        } 
        if (pack == 1 && re == 1)  { 
          int pack1; 
          pack1 = (int) (car1*.20); 
        System.out.println("Platinum Executive Package:     " + "+$" + pack1);  
          int re1; 
          re1 = (day/5)*100; 
        System.out.println("Club Member Discount:     " + "-$" + re1); 
          int total1; 
          total1 = car1 + pack1 - re1; 
          System.out.println("Total Estimate for Rental:     " + " $" + total1); 
    } 

}}}} 
+1

這將是更容易幫助你,如果你要問一個具體問題。任何幫助將不勝感激是一個聲明。你想得到什麼幫助? – axiopisty

+0

我如何編碼它只有當有一個俱樂部會員,要求沒有它的鉑金包,只是在那裏停止?當我運行它時,它會運行到那時停止。 –

+1

如何要求*鉑金包*在功能上與請求*俱樂部會員*有所不同?後者顯然是可以的。 –

回答

0

您應該修改您的OP(原始帖子)以包括您在評論中發佈的問題。

如果您只想修改代碼,只詢問他們是否需要鉑金套餐,如果他們指定他們是俱樂部會員,那麼您需要修改您的代碼,以便只讀取掃描儀的輸入對於這個問題,如果你打印的問題。

換句話說,放在if語句塊的周圍。這是最佳做法,即使對於1行語句塊也是如此。

您目前有:

... 
int re; 
re = blah.nextInt(); 
if (re == 1) 
    System.out.print("Platinum Executive Package?: 1 for yes, 0 for no: "); 
int pack; 
pack = blah.nextInt(); 
... 

你可以修改你的代碼是這樣的:

... 
int pack; 
int re = blah.nextInt(); 
if (re == 1) { 
    System.out.print("Platinum Executive Package?: 1 for yes, 0 for no: "); 
    pack = blah.nextInt(); 
} 
... 
+0

非常感謝你。很抱歉,這是我第一次嘗試編碼並尋求幫助。所以我很想念。再次感謝。 –

+0

如果這是您正在尋找的答案,請考慮將其標記爲可接受的解決方案。這是StackExchange站點的標準做法。 – axiopisty

相關問題