Define a class Bill that find telephone bill of customer having the following details:
average.
subject marks and count the number
Data Members:
int billno-
to store bill number
String name - to store customer name
String date - to store bill issue date
double amount - to store bill amount paid by customer
int surcharge - to store fixed surcharge of Rs. 100.
int calls -
to store number of calls used by customer
int rent -
to store fixed monthly rent of Rs. 300
Member functions:
(a) Bill() - a constructor initialize data members with default value.
(b) Bill() – a parameterized constructor to accept bill no, name ,date and number of calls as
parameters and initializes the surcharge & monthly rent.
(c) Calculate( ) – to calculate the telephone bill for a customer a per following conditions.
Number of calls
Date per call
First 100 calls
Surcharge + Monthly rent
Next 100 calls
Re 1 + Surcharge + monthly rent
Above 200 calls
Re 2 + Surcharge + monthly rent
(d) Display() - To display all details in following format:
Bill Number:
Name:
Number of Calls:
Date:
Surcharge:
Monthly Rent :
Bill Amount:
Create the object of class in main method and invoke the above mentioned methods to
perform the task.
Answers
Explanation:
import java.util.Scanner; public class Bill { private int bno; private String name; private int call; private double amt; public Bill() { bno = 0; name = ""; call = 0; amt = 0.0; } public Bill(int bno, String name, int call) { this.bno = bno; this.name = name; this.call = call; } public void calculate() { double charge; if (call <= 100) charge = call * 0.6; else if (call <= 200) charge = 60 + ((call - 100) * 0.8); else if (call <= 300) charge = 60 + 80 + ((call - 200) * 1.2); else charge = 60 + 80 + 120 + ((call - 300) * 1.5); amt = charge + 125; } public void display() { System.out.println("Bill No: " + bno); System.out.println("Name: " + name); System.out.println("Calls: " + call); System.out.println("Amount Payable: " + amt); } public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print("Enter Name: "); String custName = in.nextLine(); System.out.print("Enter Bill Number: "); int billNum = in.nextInt(); System.out.print("Enter Calls: "); int numCalls = in.nextInt(); Bill obj = new Bill(billNum, custName, numCalls); obj.calculate(); obj.display(); } }