Question
JAVA HELP: Create one abstract class called Number which has two non-abstract sub-classes called NumberDouble and NumberInt . Objects of type NumberDouble should hold double
JAVA HELP:
Create one abstract class called Number which has two non-abstract sub-classes called NumberDouble and NumberInt. Objects of type NumberDouble should hold double values whereas objects of type NumberInt should hold integer values. These classes should have constructors for creating such objects from primitive values of type double and int respectively, and should have private fields of the correct type to store the primitive values passed to the constructor. The Number class should declare one abstract method getNumber() that returns type double this method should be implemented by both NumberDouble and NumberInt to allow their respective stored values to be retrieved. Then create one class called GeometricFigure3 using the code from GeometricFigure2 below as the starting point. Modify the class GeometricFigure3 so that the method calcArea()returns type NumberDouble.
Then create one class called GenericCircle using the code from Circle below as a starting point. The class GenericCircle should be a subclass of GenericGeometricFigure. Modify GenericCircle so that it becomes a generic class with a type parameter T which represents any subclass of a new abstract class Number (defined above). Within your new version of class Circle(GenericCircle), T should be used as the type of the circles radius in place of double
Finally, add a static main() method to Number which creates a GenericCircle object (with type argument NumberDouble and radius 6.9) and another GenericCircle object (with type argument NumberInt and radius 6), and prints the result of calling calcArea() on those objects to the console.
Remark: You should avoid type casts in your answer!
abstract class GeometricFigure2 { public static final double PI = 3.141592653; private baslean filled; public GeometricFigure2() { filled = false; } public boolean isfitted) { return filled; } public void setFilled (kaalean filled) { this filled = filled; } public void display() { System.out.println("This is some geometric figure."); } public abstract double salsArea(); } class Circle extends Geometrisfigurs private double radius; public Circle(double radius) { this radius. = radius; } public double setacea) { return radius*radius*PI; } public void display() { System.out.println("This is a circle with radius " + radius); } }Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started