Back to Browse

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

7.7K views
Feb 27, 2022
16:41

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(); } }

Download

0 formats

No download links available.

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