Hello again, all,
I am in the process of creating a calculator GUI that calculates different answers based on inputs two main comboboxes and numbers in the appropriate textfields. The first one allows the user to choose from 18 different materials, while the second has the user choose between two different shapes. In a brief word explanation, here's how it's set up:
User chooses material.
User chooses shape.
User types in appropriate values.
'Calculate' button clicked.
If shape = rectangle, execute rectangle calculation.
Else if shape = cylinder, execute cylinder calculation.
Everything works just fine with zero errors on all 18 materials and all kinds of decimal numbers when the second shape is selected. So the math and layout is solid. However, when the first shape is selected, it returns a $0.00 answer regardless of the input values (still no red-line errors). In efforts to troubleshoot, when I have
/* Cylinder section */, the rectangle section works to a 'T'. This, I believe is caused by poor formatting in the syntax of the 'if' 'else if' in regards to the shape combobox. But, I'm not sure how to correctly format it to fix the issue. Here is a sample of the coding, if you need more I can provide it, but it's rather lengthy. Any help is much appreciated!
//If 'Rectangle' is selected: if(shapeDropDown.getSelectedIndex()==1) { //6061 if(materialDropDown.getSelectedIndex()==0) { String msg0 = "The price is: $" + currencyFormat.format((0.098*(number2*number3*number4)*3.06)); totalPrice.setText(msg0); } //2024 if(materialDropDown.getSelectedIndex()==1) { String msg1 = "The price is: $" + currencyFormat.format((0.1*(number2*number3*number4)*5.61)); totalPrice.setText(msg1); } ... //If 'Cylinder' is selected: } else if(shapeDropDown.getSelectedIndex()==2); { //6063 if(materialDropDown.getSelectedIndex()==0){ String msg0c = "The price is: $" + currencyFormat.format(((0.098*(((number1/2)*(number1/2))*3.14159*number2))*3.06)); totalPrice.setText(msg0c);} //2024 if(materialDropDown.getSelectedIndex()==1){ String msg1c = "The price is: $" + currencyFormat.format(((0.1*(((number1/2)*(number1/2))*3.14159*number2))*5.61)); totalPrice.setText(msg1c);} ...