Answer the following question using Java Creator: The OAMC company wants to make
ID: 3844453 • Letter: A
Question
Answer the following question using Java Creator:
The OAMC company wants to make a new tariff for their electricity users. Then the company introduces a new billing system for each customer by introducing a JAVA program for calculating and displaying the data for each customer. Create a java class and reads customer account number. Customer name, Number of units consumed etc... and write a function for calculating the total bill based on the conditions given below. Finally, create the main class and create object for the java class you create and call functions for displaying the output. i) If the units consumed ore below 100. the unit price becomes 1.200 OMR. ii) If the units consumed between 100 and less than 2S0 the unit price becomes 1.400 OMR. iii) If the units consumed between 250 and less than 400, the unit price becomes 2.00 OMR. iv) If the units consumed above 400, the unit price will be 2.5 OMR.Explanation / Answer
Here is your code: -
Customer.java
public class Customer {
private int customerID;
private String customerName;
private int numOfUnitsConsumed;
Customer() {
}
public Customer(int customerID, String customerName, int numOfUnitsConsumed) {
this.customerID = customerID;
this.customerName = customerName;
this.numOfUnitsConsumed = numOfUnitsConsumed;
}
public int getCustomerID() {
return customerID;
}
public void setCustomerID(int customerID) {
this.customerID = customerID;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public int getNumOfUnitsConsumed() {
return numOfUnitsConsumed;
}
public void setNumOfUnitsConsumed(int numOfUnitsConsumed) {
this.numOfUnitsConsumed = numOfUnitsConsumed;
}
public double calculateBill() {
if(this.numOfUnitsConsumed < 100) {
return this.numOfUnitsConsumed*1.200;
} else if(this.numOfUnitsConsumed >= 100 && this.numOfUnitsConsumed < 250) {
return this.numOfUnitsConsumed*1.400;
} else if(this.numOfUnitsConsumed >= 250 && this.numOfUnitsConsumed < 400) {
return this.numOfUnitsConsumed*2.000;
} else {
return this.numOfUnitsConsumed*2.500;
}
}
}
Main.java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the ID of the customer: ");
int custId= Integer.parseInt(scan.next());
System.out.print("Enter customer Name: ");
String name = scan.next();
System.out.print("Enter number of units consumed: ");
int numOfUnits = Integer.parseInt(scan.next());
Customer cust = new Customer(custId, name, numOfUnits);
scan.close();
System.out.println();
System.out.println();
System.out.println("Customer ID: "+cust.getCustomerID());
System.out.println("Customer Name: "+cust.getCustomerName());
System.out.println("Number of Units Consumed: "+cust.getNumOfUnitsConsumed());
System.out.println("Total Bill: "+new Double(cust.calculateBill()).intValue()+" OMR");
}
}
Sample Run: -
Enter the ID of the customer: 1234
Enter customer Name: Manoj
Enter number of units consumed: 250
Customer ID: 1234
Customer Name: Manoj
Number of Units Consumed: 250
Total Bill: 500 OMR