0% found this document useful (0 votes)
19 views

Java Onlinw

This Java code defines a CalculateElectricityBill class that calculates electricity bills for domestic or commercial customers based on the number of units consumed. It takes the units as a parameter, determines the billing rate based on usage tiers, and sets the billpay variable accordingly. The main method then gets customer input, calculates units consumed, creates a CalculateElectricityBill object to determine the amount due, and prints the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Java Onlinw

This Java code defines a CalculateElectricityBill class that calculates electricity bills for domestic or commercial customers based on the number of units consumed. It takes the units as a parameter, determines the billing rate based on usage tiers, and sets the billpay variable accordingly. The main method then gets customer input, calculates units consumed, creates a CalculateElectricityBill object to determine the amount due, and prints the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

*;
class CalculateElectricityBill
{
double billpay;
CalculateElectricityBill(long units)
{
int conn=0;
//domestic
if(conn==1)
{
if(units<100)
billpay=units*1.0;
else if((units<=200)&&(units>=101))
billpay=units*2.50;
else if((units>=201)&&(units<500))
billpay= units*4;
else billpay=units*6;
}
//commercial
else
{
if(units<100)
billpay=units*2.0;
else if((units<=200)&&(units>=101))
billpay=units*4.50;
else if((units>=201)&&(units<500))
billpay= units*6;
else billpay=units*7;
}
}
}
public class Main
{
public static void main(String args[])
{
String name;
long units;
int newreading,oldreading,ebno;
Scanner sc=new Scanner(System.in);
System.out.println("enter the customer name");
name = sc.nextLine(); System.out.println("enter the Eb no");
ebno=sc.nextInt();
System.out.println("enter the new reading");
newreading= sc.nextInt(); System.out.println("enter the old reading");
oldreading= sc.nextInt();
units = newreading-oldreading;
CalculateElectricityBill b=new CalculateElectricityBill(units);
System.out.println("Name::"+name);
System.out.println("Eb No::"+ebno);
System.out.println("Bill to pay : " + b.billpay);
}
}

You might also like