Final answer:
A student needs to write a program in Java with a class Data that has members height and breadth, and methods get_data() and put_data(). Inherited classes Rectangle and Triangle will compute area and perimeter of a rectangle and triangle respectively.
Step-by-step explanation:
To answer the question, we'll create a class Data in Java with two data members: height and breadth, which will be provided by the user. The class will also have two member functions: get_data() to read the values, and put_data() to display the values. We'll then create a class Rectangle that inherits from Data and implements methods areaRectangle() and perimeterRectangle() to compute the area and perimeter of a rectangle, respectively.
Similarly, we'll create another class Triangle that also inherits from Data and implements methods areaTriangle() and perimeterTriangle() to calculate the area and perimeter of a triangle. The area of a triangle can be computed using Heron's formula, which requires the lengths of all three sides. Since the question only provides height and breadth, we will assume these to correspond to a right-angled triangle's base and height for simplicity.
Example Implementation
Class Data:
// Implement the get_data and put_data methods
Class Rectangle:
// Calculate the area by multiplying height by breadth
// Calculate the perimeter by adding double the height and breadth
Class Triangle:
// Calculate the area using 0.5 * base * height
// Calculate the perimeter by adding the base, height, and hypotenuse (calculated using the Pythagorean theorem)