-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElect.java
94 lines (86 loc) · 2.67 KB
/
Elect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Author : Murali Krishna Mallela
* Roll Number : 21C51A0522
* Date : 26/09/2024
*/
import java.util.*;
public class Elect {
String meterNo;
String customerName;
int previousReading;
int presentReading;
int units;
int charge;
int extraCharge;
int totalBill;
int amount;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Elect bill = new Elect();
System.out.print("Enter Meter Number: ");
bill.meterNo = scanner.nextLine();
System.out.print("Enter Customer Name: ");
bill.customerName = scanner.nextLine();
System.out.print("Enter Previous Reading: ");
bill.previousReading = scanner.nextInt();
System.out.print("Enter Present Reading: ");
bill.presentReading = scanner.nextInt();
bill.calculateBill();
bill.displayBill();
scanner.close();
}
public void calculateBill() {
units = presentReading - previousReading;
if (units < 0) {
System.out.println("Error: Present reading cannot be less than previous reading.");
return ;
}
if (units <= 100) {
charge = 2;
} else if (units <= 300) {
charge = 4;
}
else if (units <=500) {
charge = 5;
}
else if (units <= 800) {
charge = 7;
}
else if(units <=1000) {
charge = 8;
}
else {
charge = 10;
}
amount =units * charge;
if (units<200) {
extraCharge = amount+charge*10;
}
else if(units < 400)
{
extraCharge = amount+charge*20;
}
else if(units < 600)
{
extraCharge = amount+charge*40;
}
else if(units < 1000)
{
extraCharge=amount+charge*50;
}
else {
extraCharge =amount+charge*100;
}
totalBill = extraCharge;
}
public void displayBill() {
System.out.println("Electricity Bill Details:");
System.out.println("Meter No: " + meterNo);
System.out.println("Customer Name: " + customerName);
System.out.println("Units Consumed: " + units);
System.out.println("Charge: " + charge);
System.out.println("Amount: "+amount);
System.out.println("Extra Charge: " + extraCharge);
System.out.println("Total Bill: " + totalBill);
}
}