Results 1 to 2 of 2
- 04-11-2014, 05:12 AM #1
Member
- Join Date
- Apr 2014
- Posts
- 1
- Rep Power
- 0
trouble writing if statement with combo box
Hello,
This is my first post and I'm very new to programming. I'm working on assignment for a class where I'm creating a home utility auditor. Basically the user has to pick from a list of appliances and then input various fields to calculate a total cost. When the user chooses "washer" from the list of appliances, they must enter in values for 2 separate fields, and will then click calculate to get total cost. I've been trying to implement this through an if, else statement, but it's not wanting to calculate a total cost and I'm running into errors. I've put the code below. Any help would be greatly appreciated. Thank you!
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// The calculate button will multiply the 3 fields that the user inputs:
//cost*Kw used*hours used=total cost of operation
float num1,num2, num3, result;
//now, parse the text to a type float
num1= Float.parseFloat (costField.getText ());
num2= Float.parseFloat (kilowattsField.getText ());
num3= Float.parseFloat (hoursField.getText ());
result= (float) (num1*num2*num3);
totalCost.setText(String.valueOf(result));
float num4, num5;
num4= Float.parseFloat (gallonsField.getText ());
num5= Float.parseFloat (costgallonsField.getText ());
if (jComboBox1.getSelectedItem().equals("Washer"))
{
result= (float) (num4*num5*num3);
totalCost.setText(String.valueOf(result));
}
else {
result= (float) (num1*num2*num3);
totalCost.setText(String.valueOf(result));
}
}
- 04-11-2014, 10:15 AM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Similar Threads
-
help writing a statement in java
By thclement in forum New To JavaReplies: 1Last Post: 01-24-2013, 06:04 AM -
Trouble with While Statement
By Chad.Curtiss in forum New To JavaReplies: 9Last Post: 07-20-2012, 08:03 AM -
Trouble with recursion if statement.
By david522 in forum New To JavaReplies: 3Last Post: 09-28-2011, 03:41 PM -
new to java, trouble with if statement
By Globular in forum New To JavaReplies: 8Last Post: 05-25-2011, 07:03 PM -
Combo box trouble turning into a boxing match with java
By Embercloud in forum New To JavaReplies: 1Last Post: 01-05-2011, 04:46 PM
Bookmarks