Electricity Bill Program in Java - Java Lab Programs - Java Tutorial for beginners

Published: 27 February 2022
on channel: Join To Learn
7,692
125

Step by step explanation for Generation of electricity bill java program.

Program:
(Pls note that greater than and lesser than symbols are not supported in description)

import java.util.Scanner;
class ElectBill
{
int ConsumerNo;
String ConsumerName;
int PrevReading;
int CurrReading;
int EBConn;

int units;
double bill;

void input_data()
{
Scanner sc = new Scanner(System.in);

System.out.print("Enter Consumer Number: ");
ConsumerNo = sc.nextInt();

System.out.print("Enter Consumer Name: ");
ConsumerName = sc.next();

System.out.print("Enter Previous units:");
PrevReading = sc.nextInt();

System.out.print("Enter Current Units:");
CurrReading = sc.nextInt();

System.out.print("Connection Type: 1.Domestic 2.Commercial (1 or 2):");
EBConn = sc.nextInt();

}

void calculate_bill()
{
units = CurrReading - PrevReading;
System.out.println("\n No of units: " + units);

switch(EBConn)
{
case 1: if(units greater than= 0 && units less than= 100)
bill = units * 1;
else if(units greater than 100 && units less than= 200)
bill = (100*1) + ((units-100)*2.50);
else if(units greater than 200 && units less than=500)
bill = (100*1) + (100*2.50) + ((units-200)*4);
else
bill = (100*1) + (100*2.50) + (300*4) + ((units-500)*6);
break;
case 2: if(units greater than= 0 && units less than= 100)
bill = units * 2;
else if(units greater than 100 && units less than= 200)
bill = (100*2) + ((units-100)*4.50);
else if(units greater than 200 && units less than=500)
bill = (100*2) + (100*4.50) + ((units-200)*6);
else
bill = (100*2) + (100*4.50) + (300*6) + ((units-500)*7);
break;
}

}

void display()
{
System.out.println("------------------------");
System.out.println(" ELECTRICITY BILL ");
System.out.println("------------------------");
System.out.println("Consumer Number: "+ConsumerNo);
System.out.println("Consumer Name: "+ConsumerName);
System.out.println("Consumer Previous Reading: "+PrevReading);
System.out.println("Consumer Current Readung: "+CurrReading);
System.out.println("Type of Connection: "+EBConn);
System.out.println("------------------------");
System.out.println("Total Bill in Rs." + bill);
}
}

class ElectricityBill
{
public static void main(String args[])
{

ElectBill b = new ElectBill();
b.input_data();
b.calculate_bill();
b.display();
}
}


On this page of the site you can watch the video online Electricity Bill Program in Java - Java Lab Programs - Java Tutorial for beginners with a duration of hours minute second in good quality, which was uploaded by the user Join To Learn 27 February 2022, share the link with friends and acquaintances, this video has already been watched 7,692 times on youtube and it was liked by 125 viewers. Enjoy your viewing!