My input for my program seems to be traveling to the wrong else statement in my if-else statements.
import java.util.Scanner;
import java.text.*;
public class CSCD210Lab6
{
public static void main (String [] args)
{
Scanner waterInput = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("$#,###.00");
DecimalFormat zf = new DecimalFormat("#,###.0");
//declare variables
int beginMeter, endMeter;
String customerCode;
double billingAmount,gallonsUsed;
billingAmount = 0;
System.out.print("Please Enter Your Customer Code: ");
customerCode = waterInput.next();
System.out.print("Please Enter Your Beginning Meter Reading: ");
beginMeter = waterInput.nextInt();
if(beginMeter < 0)
{
System.out.println();
System.out.print("ERROR! You Have Entered A Negative Number. The Program Will Now Close.");
System.exit(0);
}
System.out.print("Please Enter Your Ending Meter Reading: ");
endMeter = waterInput.nextInt();
if(endMeter < 0)
{
System.out.println();
System.out.print("ERROR! You Have Entered A Negative Number. The Program Will Now Close.");
System.exit(0);
}
if(endMeter > beginMeter)
{
gallonsUsed = ((double)endMeter - beginMeter)/10;
}
else
{
gallonsUsed = (1000000000-((double)beginMeter - endMeter))/10;
}
if (customerCode.equals("r")||customerCode.equals("R"))
{
billingAmount = 5.00 + (.0005 * gallonsUsed);
}
if(customerCode.equals("c")||customerCode.equals("C") && gallonsUsed <= 4000000)
{
billingAmount = 1000.00;
}
if(customerCode.equals("c")||customerCode.equals("C") && gallonsUsed > 4000000)
{
billingAmount = 1000.00 + ((gallonsUsed-4000000) * 0.00025);
}
if(customerCode.equals("i")||customerCode.equals("I")&& gallonsUsed <= 4000000)
{
billingAmount = 1000.00;
}
if(customerCode.equals("i")||customerCode.equals("I")&& gallonsUsed > 4000000 && gallonsUsed < 10000000)
{
billingAmount = 2000.00;
}
if(customerCode.equals("i")||customerCode.equals("I")&& gallonsUsed >= 10000000)
{
billingAmount = 2000.00 +(gallonsUsed * .00025);
}
System.out.println();
System.out.print("Your Customer Code is: "+customerCode);
System.out.println();
System.out.print("Your Beginning Meter Reading is: "+beginMeter);
System.out.println();
System.out.print("Your Ending Meter Reading is: "+endMeter);
System.out.println();
System.out.print("You Have Used "+zf.format(gallonsUsed)+" Gallons During This Billing Period.");
System.out.println();
System.out.print("Your Bill is: "+df.format(billingAmount));
System.out.println();
System.out.println();
System.out.print("Please Pay Promptly. We Detest Late Accounts.");
}
}
For example, if I enter c, and the total water used in less than 4,000,000 gallons, it executes the line of code for when the total gallons used is more than 4,000,000 gallons. Why?