0% found this document useful (0 votes)
26 views2 pages

Practice Q 03

The document outlines requirements for a Java program that includes an abstract class 'Shape' with subclasses 'Rectangle' and 'Circle' for calculating areas. It also defines an interface 'Movable' with a class 'Door' implementing its methods. Additionally, it describes a program to manage employee information, calculating the number of employees with salaries over 12000 and finding the maximum salary.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Practice Q 03

The document outlines requirements for a Java program that includes an abstract class 'Shape' with subclasses 'Rectangle' and 'Circle' for calculating areas. It also defines an interface 'Movable' with a class 'Door' implementing its methods. Additionally, it describes a program to manage employee information, calculating the number of employees with salaries over 12000 and finding the maximum salary.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Question 1 Write a Java program to implement the following requirements:​ 10​

1.​ Abstract Class: Shape


○​ Define an abstract class named Shape.
○​ It should have two protected properties: name (of type String) and area (of type
double).
○​ Include a public constructor in the Shape class that accepts the name parameter.
○​ Add a concrete void method named printArea, which prints the name of the shape
along with its area.
○​ Define an abstract method named calculateArea, which calculates the area of different
shapes.
2.​ Class: Rectangle
○​ Create a class Rectangle that inherits from the Shape class.
○​ Add two protected properties: length (of type double) and width (of type double).
○​ Provide a constructor for the Rectangle class that accepts length and width as
parameters and passes "Rectangle" as the name to the superclass constructor.
○​ Override the calculateArea method to compute the area of a rectangle using the
formula:
■​ area = length * width.
3.​ Class: Circle
○​ Create a class Circle that inherits from the Shape class.
○​ Add a protected property: radius (of type double).
○​ Provide a constructor for the Circle class that accepts the radius parameter and passes
"Circle" as the name to the superclass constructor.
○​ Override the calculateArea method to compute the area of a circle using the formula:
■​ area = Math.PI * radius * radius.
4.​ Interface: Movable
○​ Define an interface named Movable with two abstract methods:
■​ void open()
■​ void close()
5.​ Class: Door
○​ Create a class Door that implements the Movable interface.
○​ Implement the open() method to print: "Opening the door".
○​ Implement the close() method to print: "Closing the door".

Expected Output:
Question 2. ​ 5

Write a program which will take employee information of an office. Where the number of employees will be
provided by console as n. After this number, you will get names and ids and salaries of employees. Create
a class Employee and store the information received from the console in an array of employees. Now,
traverse and find the total number of employees who have a salary of at least 12000 or more, also print the
maximum employee salary. Please check the following sample input/output along with the explanation.​
\

You might also like