اخواني مبرمجين الجافا كل عام وانتم بخير الرجاء مساعدتي في حل هالسؤال :
Q2.1: Write a Java program according to the following specifications:
(a) Develop an interface ShapeInterface to the following specifications:
• The interface includes one method: public double getArea(). Later when getArea() is implemented in a class, it should return a number representing the area of the relevant shape.
(b) Develop a public abstract class Shape to the following specifications: (4 marks)
• The class implements ShapeInterface.
• The class has two private instance variables: int x, and int y .
• Accessor and mutator methods should be implemented for all instance variables.
© Develop a public class Circle to the following specifications: (4 marks)
• The class is a subclass of Shape.
• The class has a private instance variable int radius.
• The class has a three-argument constructor that sets the values of x, y, and radius to given values.
• The class has a one-argument constructor that sets the values of rad to given value, and x and y to zeros. This should be done by invoking the above three-argument constructor using this keyword.
(d) Develop a public class Rectangle to the following specifications: (4 marks)
• The class is a subclass of Shape.
• The class has two private instance variables int height and int width.
• The class has a four-argument constructor that sets the values of x, y, width and height to given values.
• The class has a two-argument constructor that sets the values of width and height to given values, and x and y to zeros. This should be done by invoking the above four-argument constructor using this keyword.
(e) Both Circle and Rectangle classes should: (8
• override toString() in java.lang.Object to return a string representation of the instance variables in the relevant class.
• include implementation of any further mandatory methods.
• include accessor and mutator methods for all instance variables.
Q2.2: Develop a class ShapesTest to test the classes in Q2.1. The class ShapesTest will only have the main method that should: (4 marks)
• Create a Circle instance using the three argument constructor.
• Create a Rectangle instance using the two argument constructor, and sets the values of the remaining variables using the mutator methods.
• Print on the screen the values of the instance variables of the two above instances using toString().
Q2.3: Answer the following questions: (4 marks)
(a) Can we instantiate objects of the type Shape? Justify your answer.
(b) Do we have to override getArea()in Shape class (you may try this on NetBeans)? Justify your answer
