2016-11-15 10 views
0

두 개의 라디오 버튼 중 하나를 클릭하면 새로운 고객인지 또는 재 방문 고객인지에 따라 다른 할인을 적용하는 GUI를 만들려고합니다. 선택할 수있는 각기 다른 옵션에 할인이 적용됩니다. 내 문제는 옵션을 추가하기 위해 확인란을 클릭 할 때마다 할인 혜택이 계속 유지된다는 것입니다. 처음은 옳았지만 그 이후의 모든 클릭은 할인을 더 높고 높게 만듭니다. 어떤 도움을 크게 감상 할 수JCheckBox를 토글 할 때 GUI가 컴 파운딩 할인을 유지합니다.

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

:

@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)); 
     } 

    } 

여기에 라디오 버튼에 대한 내 코드는 다음과 같습니다 여기에 체크 박스에 대한 내 코드입니다!

+1

첫째로, 당신은'isNewCustomer == TRUE '를 제거 할 수 있습니다 단지 그것이'boolean' 때문에'isNewCustomer'를 사용합니다. 둘째, 새로운 고객을 선택하지 않으면 isNewCustomer = false'를 설정해야합니다. 셋째, 당신은'tireRotation'을 오버라이드하고 있는데, 이것은 기본 금액을 가정합니다. 나는 대신에 새로운 변수 인'tireRotationCost = tireRotation * (1.0-new/regularCustomerDiscount);'를 사용해야한다고 생각합니다. 이 방법은 매번 비용을 겹쳐 쓰지 않고 합성합니다. –

+0

두 토글을 모두 처리하는 한 방법으로 수행 할 수 있습니다. – Sedrick

답변

0

방금 ​​질문을 다시 읽습니다. 전역 변수를 만듭니다. 토글 상자에서 finalCost 전역 변수를 설정합니다. 가변 설정하는 경우 예 이내 :

전역 변수 :

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; 
} 
S

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; 
}