Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
20.6k views
in Computer by (49.9k points)
closed by

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

Number of calls: 

Rate 1 – 100: Only rental charge 

101 – 200: 60 paise per call + rental charge 

201 – 300: 80 paise per call + rental charge 

Above 300: 1 rupee per call + rental charge 

The details of both the classes are given below:

Class name: Detail 

Data members/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 details of the customer 

Class name: Bill 

Data members/instance variables: 

n: to store the number of calls 

amt: to store the amount to be paid by the customer 

Member functions: Bill (…): parameterized constructor to assign values to data members of both classes and to initialize amt = 0.0 

void cal(): calculate the monthly telephone charge as per the chart is given above 

void show(): displays 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.

1 Answer

+1 vote
by (49.0k points)
selected by
 
Best answer

class Detail 

protected String name, add; 

protected long telno; 

protected double rent; 

public Detail (String n, String a, long t, double r) 

name = n; 

add = a; 

telno = t; 

rent = r; 

void show () 

System.out.println(name + " " + add + " " + telno + " " + rent); 

}

class Bill extends Detail 

{ int n; 

double amt; 

public Bill (String nm, string ad, long tn, double rn, int, n1) 

super (nm, ad, tn, rn): n = n1; amt = 0.0; 

void cal () { if (n > = 1 && n < = 100) { amt = rent; 

else if (n > 100 && n < = 200) 

amt = rent + (n - 100) * 0.60; 

}

else if (n > 200 && n< = 300) 

amt = rent + 100 * 0.60 + (n - 200) * 0.80: 

}

 else if (n > 300) 

amt = rent + (0.60 * 100) + (0.80 * 100) + (n - 300) * 100); 

void show() 

super.show(); 

System.out.println("Amount to be paid = "+amt/100 + "Rs"); 

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...