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

Publicado el: 27 febrero 2022
en el canal de: 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();
}
}


En esta página del sitio puede ver el video en línea Electricity Bill Program in Java - Java Lab Programs - Java Tutorial for beginners de Duración hora minuto segunda en buena calidad , que subió el usuario Join To Learn 27 febrero 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 7,692 veces y le gustó 125 a los espectadores. Disfruta viendo!