0

2つのラジオボタンの1つをクリックしたときに、新規顧客かリピート顧客かによって異なる割引が適用されるGUIを作成しようとしています。あなたが選ぶことができるそれぞれの異なるオプションに割引が適用されます。私の問題は、オプションを追加するためにチェックボックスをクリックするたびに、割引を複合し続けるということです。初めての方は正しいですが、それ以降はクリックするたびに割引が高くなります。ここでは、チェックボックスのための私のコードは次のとおりです。ここでJCheckBoxを切り替えると、GUIが複合割引を維持する

@FXML 
    void tires(ActionEvent event) { 
     if(isNewCustomer==true){ 
      tireRotation=tireRotation*(1.0-newCustomerDiscount); 
      //costLabel.setText("$ " +DF.format(cost)); 
     }else{ 
      tireRotation=tireRotation*(1.0-regularCustomerDiscount); 
      // costLabel.setText("$ " +DF.format(cost)); 
     } 

     if(tireBox.isSelected()){ 
      cost+=tireRotation; 
      costLabel.setText("$ " +DF.format(cost)); 

     } else { 
      cost =cost-tireRotation; 
      costLabel.setText("$ " +DF.format(cost)); 
     } 

    } 

は、ラジオボタンの私のコードは次のとおりです。

@FXML 
void newCustomer(ActionEvent event) { 
    if (newCustomer.isSelected()){ 
     isNewCustomer=true; 
    } 
} 

任意の助けをいただければ幸いです!

+1

まず第一に、あなたは 'isNewCustomer == true'をを削除し、ちょうどそれが' boolean'あるので、 'isNewCustomer'を使用することができます。次に、新しい顧客が選択されていない場合は、isNewCustomer = falseを設定する必要がありますが、私はそれを見ません。第三に、あなたは 'tireRotation'をオーバーライドしています。これは基本量を仮定しています。代わりに、新しい変数 'tireRotationCost = tireRotation *(1.0-new/regularCustomerDiscount); 'を使うべきだと思います。この方法では、それは合成されず、毎回コストを上書きします。 –

+0

両方のトグルを扱う1つのメソッドで実行できることがあります。 – Sedrick

答えて

0

私はちょうどあなたに質問を再読します。グローバル変数を作成します。トグルボックスのメソッドで、finalCostグローバル変数を設定します。 は、実施例1F内の変数を設定する:

グローバル変数:

double finalCost = 0; 
double initialCharge = 200; 
double discount= 50; 
double newAccountDiscount= 25; 

最初方法:

if(tireBox.isSelected() && newCustomer.isSelected()) 
{ 
    finalCost = initialCharge - discount - newAccountDiscount; 
} 
else if(tireBox.isSelected()) 
{ 
    finalCost = initialCharge - discount; 
} 
else if(newCustomer.isSelected()) 
{ 
    finalCost = initialCharge - newAccountDiscount; 
} 
else 
{ 
    finalCost = initalCharge; 
} 

秒econd方法:

if(tireBox.isSelected() && newCustomer.isSelected()) 
{ 
    finalCost = initialCharge - discount - newAccountDiscount; 
} 
else if(tireBox.isSelected()) 
{ 
    finalCost = initialCharge - discount; 
} 
else if(newCustomer.isSelected()) 
{ 
    finalCost = initialCharge - newAccountDiscount; 
} 
else 
{ 
    finalCost = initalCharge; 
} 
関連する問題