To develop a Java application to generate Electricity bill. Create a class with the following members: Consumer no., consumer name, previous month reading, current month reading, type of EB connection (i.e domestic or commercial). Compute the bill amount using the following tariff.
Question
To develop a Java application to generate Electricity bill. Create a class with the following members: Consumer no., consumer name, previous month reading, current month reading, type of EB connection (i.e domestic or commercial). Compute the bill amount using the following tariff.
Solution 1
Sure, here is a simple Java application that meets your requirements:
public class ElectricityBill {
private String consumerNo;
private String consumerName;
private int previousMonthReading;
private int currentMonthReading;
private String typeOfConnection;
public ElectricityBill(String consumerNo, String consumerName, int previousMonthReading, int currentMonthReading, String typeOfConnection) {
this.consumerNo = consumerNo;
this.consumerName = consumerName;
this.previousMonthReading = previousMonthReading;
this.currentMonthReading = currentMonthReading;
this.typeOfConnection = typeOfConnection;
}
public double computeBill() {
int unitsConsumed = currentMonthReading - previousMonthReading;
double billAmount = 0;
if (typeOfConnection.equals("domestic")) {
if (unitsConsumed <= 100) {
billAmount = unitsConsumed * 1;
} else if (unitsConsumed <= 200) {
billAmount = 100 + (unitsConsumed - 100) * 2.5;
} else {
billAmount = 100 + 250 + (unitsConsumed - 200) * 4;
}
} else if (typeOfConnection.equals("commercial")) {
if (unitsConsumed <= 100) {
billAmount = unitsConsumed * 2;
} else if (unitsConsumed <= 200) {
billAmount = 200 + (unitsConsumed - 100) * 4.5;
} else {
billAmount = 200 + 450 + (unitsConsumed - 200) * 6;
}
}
return billAmount;
}
}
This class has five private members: consumerNo, consumerName, previousMonthReading, currentMonthReading, and typeOfConnection. The constructor initializes these members.
The computeBill method calculates the bill amount based on the type of connection and the number of units consumed. The number of units consumed is calculated as the difference between the current month reading and the previous month reading.
The tariff rates are assumed as follows (you can change them as per your requirements):
- For domestic connections:
- 1 unit per unit for the first 100 units
- 2.5 units per unit for the next 100 units
- 4 units per unit for units above 200
- For commercial connections:
- 2 units per unit for the first 100 units
- 4.5 units per unit for the next 100 units
- 6 units per unit for units above 200
Please note that this is a simple implementation and does not include error checking or handling for invalid inputs.
Solution 2
Sure, here is a simple implementation of the problem in Java:
public class ElectricityBill {
private String consumerNo;
private String consumerName;
private int previousMonthReading;
private int currentMonthReading;
private String typeOfConnection;
public ElectricityBill(String consumerNo, String consumerName, int previousMonthReading, int currentMonthReading, String typeOfConnection) {
this.consumerNo = consumerNo;
this.consumerName = consumerName;
this.previousMonthReading = previousMonthReading;
this.currentMonthReading = currentMonthReading;
this.typeOfConnection = typeOfConnection;
}
public double computeBill() {
int unitsConsumed = currentMonthReading - previousMonthReading;
double billAmount = 0;
if (typeOfConnection.equals("domestic")) {
if (unitsConsumed <= 100) {
billAmount = unitsConsumed * 1;
} else if (unitsConsumed <= 200) {
billAmount = 100 + (unitsConsumed - 100) * 2.5;
} else {
billAmount = 100 + 250 + (unitsConsumed - 200) * 4;
}
} else if (typeOfConnection.equals("commercial")) {
if (unitsConsumed <= 100) {
billAmount = unitsConsumed * 2;
} else if (unitsConsumed <= 200) {
billAmount = 200 + (unitsConsumed - 100) * 4.5;
} else {
billAmount = 200 + 450 + (unitsConsumed - 200) * 6;
}
}
return billAmount;
}
}
This class has a constructor that initializes all the required fields. The computeBill method calculates the bill amount based on the type of connection and the number of units consumed. The tariff rates are assumed and you can replace them with the actual rates.
You can create an object of this class and call the computeBill method to get the bill amount:
public class Main {
public static void main(String[] args) {
ElectricityBill bill = new ElectricityBill("123", "John Doe", 500, 800, "domestic");
System.out.println("The bill amount is: " +
Similar Questions
Write a program in java to input number of water units consumed.Get the details like consumer name, consumer number, consumer type and the no. of units consumed. If the consumer is “Domestic” compute the total bill amount according to following slab.Below 150 Rs 250151 to 175 Re 1.00 per unit176 to 300 Rs 1.75 per unitAbove 300 Rs 2.25 per unitIf the consumer type is : “Industry” use the following rulesBelow150 Rs 200/=151 to 175 Re 0.75 per unitNext 176 to 300 Rs 1per unitAbove 300 Rs 2 per unit
Given the number of units consumed by a domestic user in Tamil Nadu, write a program to calculate the electricity bill. The Tamil Nadu electricity bill tariff for domestic user is given belowTamilNadu Electricity BillConsumption upto 500 unitUnits from To Units Unit Cost / KWH 1 100 0 101 200 2.25 201 400 4.50 401 500 6.00Consumption above 500 units 1 100 0 101 400 4.50 401 500 6 501 600 8 601 800 9 801 1000 10Above 1000 units 11 Input Format:Give the number of units consumed:Output Format:Tariff: Sample Input: 400Sample Output:
Create a class for Electricity for N flats of an apartment. The required details are Flat number, EB meter number, Owner name, Previous month reading (in Units), current month reading (in Units), amount. Amount will be calculating as below:0-100 = Minimum charges ₹100.00101-500 = 2.50 ₹ per unit501-1000 = 5.00 ₹ per unitAbove 1000 =7.50 ₹ per unit Write appropriate functions to perform the following:Display the flat number, owner name, previous reading and current reading.Floor will be identified from the first digit of a flat number. For 1001 – first floor, 2005 – second floor, 5010- Fifth floor. Display the floor wise details with total units and total amount.Input format:Enter the flat No:Enter the flat owner Name:Enter the previous reading:Enter the current reading:Output format:Total Units:Total amount:
Write a program to input the electricity unit consumed and calculate the total electricity bill according to the given conditions: For the first 50 units Rs. 3.50/unit For the next 100 units Rs. 4.50/unit For the next 100 units Rs. 5.20/unit For units above 250 Rs. 6.75/unit An additional surcharge of 20% is added to the bill.Input format :The input consists of the units consumed.Output format :The output prints the final bill amount.Round off the output to two decimal places.Refer to the sample output for formatting specifications.Sample test cases :Input 1 :50Output 1 :210.00Input 2 :150Output 2 :750.00Input 3 :250Output 3 :1374.00Input 4 :300Output 4 :1779.00
Write a Java program to manage billing information for customers. The program should allow the user to input details for multiple customers and bills. For each customer, the program should prompt the user to enter a customer ID and name. For each bill, the program should prompt the user to enter a bill number, amount, date, and the corresponding customer ID. Once the user has input all the necessary information, the program should allow the user to search for bills by customer ID. Upon entering a customer ID, the program should display all bill amounts, dates, and numbers associated with that customer ID. Frame the program using classes for Customer and Bill, and implement methods to retrieve customer and bill details. Sample Input 3 // Number of Customers 1 // Customer IDJai // Customer Name 2Sakthi 3John 5 // Number of Bills 11 // Bill Number45663 // Bill Amount02/12/2023 // Bill Date2 // Customer ID 4489609/12/20232 77896509/04/20231 99675404/11/20221 33876511/11/202332 Sample Output 1145663.002/12/202344896.009/12/2023
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.