Variable from block is put into a calculation but throws off wrong reading
- by user2926620
I am having troubles with trying to retrieve a double variable that is already established outside the block and called inside but I want to return the value of the same variable so that I can apply it to a calculation.
the variable that I want returned is:
double quarter = 0;
but when I plug it into quarter in my first else/if statement, it plugs in 0 and not the value in my switch block. What can I do to retrieve the value?
double quarter = 0;
//Date entry will be calculated by how much KW user enters
switch (input)
{
case "2/15/13":
quarter = kwUsed * 0.10;
break;
case "4/15/13":
quarter = kwUsed * 0.12;
break;
case "8/15/13":
quarter = kwUsed * 0.15;
break;
case "11/15/13":
quarter = kwUsed * 0.15;
break;
default:
System.out.println("Invalid date");
}
//Declaring variables for calculations
double base = 0;
double over = 0;
double excess = 0;
double math1 = 0;
double math2 = 0;
//KW Calculations
if (kwUsed <= 350)
{
base = quarter;
}else if (kwUsed <= 500)
{
math1 = ((kwUsed - 350) * quarter);
base = ((kwUsed * quarter) - math1);
over = ((math1 * 0.1) + math1);
}else if (kwUsed > 500)
{
math2 = ((kwUsed - 350) * 0.1);
base = ((kwUsed * 0.1) - math2);
math2 = ((kwUsed -350) - 50);
over = ((math2 * 0.1) + (15 * 0.1));
double math3 =((kwUsed - 500) * 0.1);
excess = ((math3 * 0.25) + math3);
}
Edited to clarify question.