2016-04-10 10 views
-3

コードが正常に機能しないステートメントと合計が正しく出力されない場合、プログラムは両方とも実行されます。何が間違っているのか分かりません。これが機能するために私は何を変える必要がありますか?方向は以下のとおりです。/elseがfalseステートメント//メソッドを除外しない場合は?

フィットネスセンターの会員になるための費用は以下の通りです:(a)シニア 市民割引30%; (b)メンバーシップを購入し、12月または 月分を支払った場合、割引は15%です。 (c)5つ以上のパーソナルトレーニングセッションが購入された場合、各セッションの割引は20%です。 新しいメンバシップのコストを決定するメニュー駆動型プログラムを作成します。 あなたのプログラムには、 フィットネスセンターとその料金に関する一般情報、必要なすべての情報を入手する方法、会員費を決定する方法、および会員資格を決定する方法が記載されている必要があります。 適切なパラメータを使用して、メソッドの内外に情報を渡します。

どのような方法を使用しますか?

double grossdiscount1,grossdiscount2,grossdiscount3; 
    double grossprice1,grossprice2,grossprice3; 

    //end result of box calculation 
    double answerbox1,answerbox2,answerbox3; 
    double answerbox1b,answerbox2b,answerbox3b; 
    //Jtext inputs 
    double box1,box2,box3; 

    double discount1 = 0.30 ; 
    double discount2 = 0.20 ; 
    double discount3 = 0.15 ; 
    // prices PT=personal training MT=montly price 
    double pricePT =50.00; 
    double priceMT =100.00; 






    box1 = Double.parseDouble(jTextField1.getText()); 
    box2 = Double.parseDouble(jTextField2.getText()); 
    box3 = Double.parseDouble(jTextField3.getText()); 
// i brought these out of the if statement because the program won't run without 
// them being stated 
answerbox1b=box1*100; 
grossdiscount1=(box1*priceMT)*discount3;// the amount saved 
grossprice1=(box1*priceMT); 
answerbox1=(grossprice1-grossdiscount1); 
answerbox2b=(box2*pricePT); 
grossdiscount2=(box2*pricePT)*discount2;// the amount saved 
grossprice2=(box2*pricePT); 
answerbox2=(grossprice2-grossdiscount2); 

double total = answerbox1+answerbox2+answerbox1b+answerbox2b; 
grossdiscount3=(total*discount3);// the amount saved 
grossprice3=total; 
answerbox3=(grossprice3-grossdiscount3); 




    if(box1<11) 
    { 
    answerbox1b=box1*100; 
    } 
     else if(box1>12) 
     { 
     grossdiscount1=(box1*priceMT)*discount3;// the amount saved 
     grossprice1=(box1*priceMT); 
     answerbox1=(grossprice1-grossdiscount1); 
     } 

    if(box2<5) 
    { 
    answerbox2b=(box2*pricePT); 
    } 
     else if(box2>=5) 
     { 
     grossdiscount2=(box2*pricePT)*discount2;// the amount saved 
     grossprice2=(box2*pricePT); 
     answerbox2=(grossprice2-grossdiscount2); 
     } 

    if(box3==1) 
    { 
    grossdiscount3=(total*discount3);// the amount saved 
     grossprice3=total; 
     answerbox3=(grossprice3-grossdiscount3); 
    } 
     else if(box3==0); 
     { 

     } 


    jTextField4.setText(String.valueOf(total));  
+3

'それ以外の場合(BOX1> 12)のいずれかを確認することをお勧めします;' - '削除;'は – Eran

+0

'if'文が「ハングしませんアップ'。これはブロックする可能性のある条件を評価し、1つまたは2つのステートメントのうちゼロまたは1つを実行することを除いて、ハングアップすることはありません。 – EJP

+0

しかし、プログラミングはまだ動作しません私はコアを持っていますが、間違って私は最終的な出力thatsと同時に両方のifとelseを実行するようになった – mikeg4523

答えて

1

else if文が正しく書き込まれません。を削除します。正しい流れのために。

そして私はまた、あなたがJavaで比較ダブルスに関連するスレッド

+0

あなたはこれを引き起こすダブルスを言っていますか? – mikeg4523

+0

私が見る主な問題は、このステートメントは正しくないということです。else if(box1> 12);これは、大括弧の間の次のステートメントも同様に実行されることを意味します。 ;を取り除く。また、Java(およびその他のプリミティブ型)の倍精度を比較すると予期しない出力が発生する可能性があることを考慮に入れてください – Jorge

+0

浮動小数点数または単純なelseステートメントを使用する必要があることを意味します – mikeg4523

関連する問題