icse-promo

Question

A super class Detail has been defined to store the details of a customer.Define a sub class Bill to compute the monthly telephone charge of the customer as per the chart given below:

				
					NUMBER OF CALLS     RATE
1-100               only rental Charge
101-200             60 paisa per call +rental charge
201-300             80 paisa per call+rental charge
Above 300           1 rupee per call + rental charge
				
			

The details of both the classes are given below:
Classname:Detail
Data member / instance variables:
name: to store the name of the customer
address:to store the address of the customer
telno:to store the phone number of the customer
rent:to store the monthly rental charge
Member functions:

Detail(…): parameterized constructor to assign values to data members
void show(): to display the detail of the customer

Classname:Bill

Data members / instance variables:
n: to store the number of calls
amt:to store the amount to be paid by the customer

Member function:
Bill(…):parameterized constructor to assign value to data member of both classes and to initialize amt=0.0

void cal():calculates the monthly tel phone charge as per the chart given above

void show( ):display the details of the customer and amount to be paid

Specify the class Detail giving details of the constructor() and void show(). Using the concept of inheritance , specify the class Bill giving details of the constructor( ) , void cal() and void show().
THE MAIN() FUNCTION AND ALGORITHM NEED NOT BE WRITTEN

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					public class Detail
{
    String name,address;
    long telno;
    double rent;
    Detail(String n,String a,long t,double r)
    { 
        name=n;
        address=a;
        telno=t;
        rent=r;
    }
    void show()
    {
        System.out.println("Name:"+name);
        System.out.println("Address:"+address);
        System.out.println("Telephone Number:"+telno);
        System.out.println("MonthlyRent:"+rent);
    }
}


public class  Bill extends  Detail
{
    int n;
    double amt;
    Bill(String a,String b,long c,double d,int e)
    {
        super(a,b,c,d);
        n=e;
        amt=0.0;
    }
    void cal()
    {
        if(n>=1 && n<=100)
        {
            amt=rent;
        }
        else if(n>=101 && n<=200)
        {
            amt=n*0.6+rent;
        }
        else if(n>=201 && n<=300)
        {
            amt=n*0.8+rent;
        }
        else if(n>300)
        {
            amt=n+rent;
        }
    }
    void show()
    {
        super.show();
        System.out.println("Number of calls="+n);
        System.out.println("Amount to pay="+amt);
    }
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *