Calculator does not work, does not add weekly, monthly or yearly correctly
Hi I am making a calculator where the user inputs his/her income (wages, loans, other) and spending (rent, food, other). I am an if else statement to add up the input fields as the user can input the numbers according to weekly, monthly or yearly. It allos me to run the code but when I input 10 pounds in each of the 3 fields the result is 30 but it should have calculated as 10 * 4.3333333 for each of the three fields.
The if else statement is below;
double totalIncome = num1 + num2 + num3;
double totalSpending = num4 + num5 + num6;
double result = 0;
if (op1.equals("Weekly"))
result = num1 * 4.3333333;
else if (op1.equals("Monthly"))
result = num1;
else if (op1.equals("Yearly"))
result = num1 / 12;
else if
(op2.equals("Weekly"))
result = num2 * 4.3333333;
else if (op2.equals("Monthly"))
result = num2;
else if (op2.equals("Yearly"))
result = num2 / 12;
else if
(op3.equals("Weekly"))
result = num3 * 4.3333333;
else if (op3.equals("Monthly"))
result = num3;
else if (op3.equals("Yearly"))
result = num3 / 12;
TotalIncomeField.setText( "" + totalIncome);
THE WHOLE STATEMENT LOOKS LIKE;
try {
double num1 = Double.parseDouble(LoansField.getText());
double num2 = Double.parseDouble(WagesField.getText());
double num3 = Double.parseDouble(OtherField.getText());
double num4 = Double.parseDouble(RentField.getText());
double num5 = Double.parseDouble(FoodField.getText());
double num6 = Double.parseDouble(OtherField2.getText());
String op1 = (String)LoanComboBox.getSelectedItem();
String op2 = (String)WagesComboBox.getSelectedItem();
String op3 = (String)OtherComboBox.getSelectedItem();
String op4 = (String)RentComboBox.getSelectedItem();
String op5 = (String)FoodComboBox.getSelectedItem();
String op6 = (String)Other2ComboBox.getSelectedItem();
double totalIncome = num1 + num2 + num3;
double totalSpending = num4 + num5 + num6;
double result = 0;
if (op1.equals("Weekly"))
result = num1 * 4.3333333;
else if (op1.equals("Monthly"))
result = num1;
else if (op1.equals("Yearly"))
result = num1 / 12;
else if
(op2.equals("Weekly"))
result = num2 * 4.3333333;
else if (op2.equals("Monthly"))
result = num2;
else if (op2.equals("Yearly"))
result = num2 / 12;
else if
(op3.equals("Weekly"))
result = num3 * 4.3333333;
else if (op3.equals("Monthly"))
result = num3;
else if (op3.equals("Yearly"))
result = num3 / 12;
TotalIncomeField.setText( "" + totalIncome);
if
(op4.equals("Weekly"))
result = num4 * 4.3333333;
else if (op4.equals("Monthly"))
result = num4;
else if (op4.equals("Yearly"))
result = num4 / 12;
else if
(op5.equals("Weekly"))
result = num5 * 4.3333333;
else if (op5.equals("Monthly"))
result = num5;
else if (op5.equals("Yearly"))
result = num5 / 12;
else if
(op6.equals("Weekly"))
result = num6 * 4.3333333;
else if (op6.equals("Monthly"))
result = num6;
else if (op6.equals("Yearly"))
result = num6 / 12;
TotalSpendingField.setText( "" + totalSpending);
} catch (NumberFormatException ex) {
}
}

