-
Notifications
You must be signed in to change notification settings - Fork 6
/
Electricity Board.java
85 lines (81 loc) · 2.18 KB
/
Electricity Board.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
//Electricity Board
//CustomerDetails
public class CustomerDetails {
private String customerId;
private String customerName;
private long phoneNumber;
private String city;
private double unitConsumed;
private double costPerUnit;
public void setCustomerId(String customerId){
this.customerId=customerId;
}
public void setCustomerName(String customerName){
this.customerName=customerName;
}
public void setPhoneNumber(long phoneNumber){
this.phoneNumber=phoneNumber;
}
public void setCity(String city){
this.city=city;
}
public void setUnitConsumed(double unitConsumed){
this.unitConsumed=unitConsumed;
}
public void setCostPerUnit(double costPerUnit){
this.costPerUnit=costPerUnit;
}
public String getCustomerId(){
return customerId;
}
public String getCustomerName(){
return customerName;
}
public long getPhoneNumber(){
return phoneNumber;
}
public String getCity(){
return city;
}
public double getUnitConsumed(){
return unitConsumed;
}
public double getCostPerUnit(){
return costPerUnit;
}
public CustomerDetails(String customerId, String customerName, long
phoneNumber, String city, double unitConsumed, double costPerUnit){
this.customerId=customerId;
this.customerName=customerName;
this.phoneNumber=phoneNumber;
this.city=city;
this.unitConsumed=unitConsumed;
this.costPerUnit=costPerUnit;
}
public double calculateElectricityBill(){
return(unitConsumed*costPerUnit);
}
}
//================================================//
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
CustomerDetails c = new
CustomerDetails("Sample","Sample",123456789,"Sample",12.00,13.00);
System.out.println("Enter Customer Id");
c.setCustomerId(sc.nextLine());
System.out.println("Enter Customer Name");
c.setCustomerName(sc.nextLine());
System.out.println("Enter Phone Number");
c.setPhoneNumber(sc.nextLong());
System.out.println("Enter City");
c.setCity(sc.next());
System.out.println("Enter Units Consumed");
c.setUnitConsumed(sc.nextDouble());
System.out.println("Enter Cost per Units");
c.setCostPerUnit(sc.nextDouble());
double amount=c.calculateElectricityBill();
System.out.printf("Amount to be paid is Rs.%.2f",amount);
}
}