import java.util.Scanner;
public class waterBill21
{
public static void main (String[] args)
{
//***********************
//begin while loop here, the while loop must wrap the whole program
// to create repetition
//***********************
{
String accountName;
int accountNum;
double gallonsUsed;
String letterType;
double amount = 0;
int another;
double line;
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to the Onondaga Water Bill Calculator");
System.out.println();
System.out.println("Please enter your account name: ");
accountName = scan.nextLine();
System.out.println("Please enter your 5 digit account number: ");
accountNum = scan.nextInt();
System.out.println("please enter the number of gallons used this quarter: ");
gallonsUsed = scan.nextDouble();
System.out.print("please choose from the following account types: \n"+ "\n H for residential" + "\n C for commercial" + "\n I for Industrial");
letterType = scan.nextLine();
switch (letterType){
case "H":
System.out.println("Account Type: " + "Residential");
line = 22.09;//here we initialise it...and it is only this value if case is H
if (gallonsUsed<=10000)
//when the gallons used is less than 10000
{
//divide 10000 by 1000 and multiply by 2.42
//the add line
amount=(gallonsUsed/1000)*2.42;//the value for water in a home is going to be charged the same for every first 10000 gallons used
amount=amount+22.09;//we are adding line fee to amount
}
else if(gallonsUsed>10000 && gallonsUsed<=23000)
//if gallons if >10000 and less than or = 23000
{
amount= (10000/1000)*2.42; //remember first 10000 gallons used will be charged seperatetly;
double y=gallonsUsed-10000; //now we have been charged for the first 10000 gallons
//now we have to be charged for the next 130000 gallons we use
//when you use 10000 gallons you are charged 2.42 so before 10000 i am not charge? you are charged 2.42 untill you reach 10000.....when you go higher than 10000, they start to charge you 3.22 // i get it now
//good
amount=amount+(((y)/1000)*3.22);
amount=amount+ line; //line is added to the amount
}
else
{
amount= (10000/1000)*2.42;//first 10000
double x=gallonsUsed-10000; //get value for next 13000
amount=amount+(((23000)/1000)*3.22);
x=x-23000;//values thar exceeded 23000;
amount=amount+(((x)/1000)*4.03);//get values that exceeded 23000
amount=amount+line;//add line
}
System.out.println("Gallons Used: " + gallonsUsed);
System.out.println("Gallons used: " + amount);
break;
case "C":
System.out.println("Account Type: " + "Commercial");
amount = (gallonsUsed/1000)* 2.65;
amount = amount + 22.09;
System.out.println("Gallons used: " + gallonsUsed);
System.out.println("Amount Due: " + "$"+ amount);
break;
case "I":
System.out.println("Account Type: " + "Industrial");
line = 18.41;
if (gallonsUsed>=200000)
{
amount=(gallonsUsed/1000)* 2.16;
amount=amount+ line;
}
else if (gallonsUsed>200000 && gallonsUsed<=2500000)
{
amount= (200000/1000)*2.16;
double y=gallonsUsed-200000;
amount=amount+(((y)/1000)*1.73);
amount=amount+ line;
}
else if (gallonsUsed>2500000 && gallonsUsed<=2700000)
{
amount= (2500000/1000)*1.73;
double y=gallonsUsed-2500000;
amount=amount+(((y)/1000)*4.03);
amount=amount+ line;
}
else
{
amount= (200000/1000)*2.16;
double x=gallonsUsed-200000;
amount=amount+(((2700000)/1000)*1.73);
x=x-2700000;//values thar exceeded 2700000;
amount=amount+(((x)/1000)*4.03);
amount=amount+ line;
}
System.out.println("Gallons Used: " + gallonsUsed);
System.out.println("Amount Due: " + amount);
break;
default:
System.out.println("Error, Please try again");
} //end switch
} //end while
}//end main
}//end class
1 Response
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.