-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectricity_bill.java
More file actions
70 lines (65 loc) · 1.67 KB
/
electricity_bill.java
File metadata and controls
70 lines (65 loc) · 1.67 KB
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
import java.util.*;
public class electricity_bill{
int current_units,previous_units,diff;
String Customer_name,Customer_ID;
double amount;
public void get()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of units used in current month:");
current_units=sc.nextInt();
System.out.println("Enter the no of units used in previous month:");
previous_units=sc.nextInt();
System.out.println("Enter the name of the customer:");
Customer_name=sc.next();
System.out.println("Enter the Customer ID:");
Customer_ID=sc.next();
}
public void display()
{
diff=(current_units-previous_units);
if (diff<=100) {
System.out.println("Name of the customer:"+Customer_name+"\n"+"Customer ID:"
+Customer_ID+"\n"+"Extra units used:"+diff+"\n"+"Amount to be paid:"+amount);
}
if(diff>500)
{
System.out.println("Name of the customer:"+Customer_name+"\n"+"Customer ID:"
+Customer_ID+"\n"+"Extra units used:"+diff+"\n"+"Amount to be paid:"+amount);
}
}
public void calc()
{
int diff=(current_units-previous_units);
if (diff<=100) {
amount= 0;
}
else if(diff>100 && diff<=200) {
amount = 1.5*(diff);
}
else if(diff>200 && diff<=500) {
amount= 3*(diff);
}
else {
amount= 6.6*(diff);
}
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter the no of customers:");
n=sc.nextInt();
electricity_bill ob[]=new electricity_bill[20];
for (int i=0;i<n;i++)
{
ob[i]=new electricity_bill();
ob[i].get();
}
System.out.println("Display the customer details who used less than 100 units and greater than 500 units..!!!");
for(int i=0;i<n;i++) {
ob[i].calc();
ob[i].display();
}
}
}