Page 281 - CA_Blue( J )_Class10
P. 281
Program 7 Define a class Telephone having the following description:
Instance Variables / Data Members
int prv, pre : to store the previous and present meter reading
int call : to store the calls made (i.e. pre – prv)
String name : to store the name of the customer
double amt : to store the amount
double total : to store the total amount to be paid
Member Methods
void input ( ) : to input the previous reading, present reading and name of the
customer
void cal ( ) : to calculate the amount and the total amount to be paid
void display ( ) : to display the name of the customer, calls made, amount and
total amount to be paid in the following format:
Name Calls Amount Total Amount
– – – –
Write a program to compute the monthly bill to be paid according to the given conditions:
Calls made Rate
Up to 100 calls No Charge
For the next 100 calls 90 paise per call
For the next 200 calls 80 paise per call
More than 400 calls 70 paise per call
However, every customer has to pay Rs. 180 per month as monthly rent for availing the service.
1 import java.util.*;
2 class Telephone
3 {
4 int prv, pre,call;
5 String name;
6 double amt,total;
7
8 void input()
9 {
10 Scanner sc=new Scanner(System.in);
11 System.out.println("Enter the name:");
12 name=sc.next();
13 System.out.println("Enter the previous meter reading:");
14 prv=sc.nextInt();
15 System.out.println("Enter the present meter reading:");
16 pre=sc.nextInt();
279
Class as the Basis of all Computation 279

