Java code for the following inheritance hierarchy figure..
1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point.
Provide constructor for initialising two instance variables.
Provide set and get methods for each instance variable,
Provide toString method to return formatted string for a point coordinates.
2. Create class Circle, its inheritance from Point.
Provide a integer private radius instance variable.
Provide constructor to initialise the center coordinates and radius for a circle,.In the constructor it must call its superclass constructor by using super(x,y);
Provide set and get for the radius instance variable.
Provide two methods for calculating its area and perimeter.
Provide a toString method to return a formatted string for circle features. In the process, it must call its superclass toString method by using super.toString().
3. Similar to the above class Circle definition, Design Rectangle class.
4. Similar to the above class Rectangle definition, Design Cube class,
It has a hight instance variable.
Calculate the surface area and volume for a Cube.
5. Design a test-class to test the above four classes functionality
It creates four objects for these classes and calls the corresponding methods to test complete functionality for each class.

class Point
{
private int x;
private int y;
public Point()
{
this.x = 0;
this.y = 0;
}
public Point(int x,int y)// constructor
{
this.x = x;
this.y = y;
}
// set and get methods
public int getX()
{
return this.x;
}
public int getY()
{
return this.y;
}
public void setX(int x)
{
this.x = x;
}
public void setY(int y)
{
this.y = y;
}
public String toString()
{
return "Point("+getX() +","+getY()+")";
}
};
class Circle extends Point
{
private int radius;
public Circle()
{
super(0,0);
radius = 0;
}
public Circle(int x,int y,int radius)// constructor
{
super(x,y);
this.radius = radius ;
}
// set and get methods
public int getRadius()
{
return radius;
}
public double getArea() //compute the area of the circle
{
double area;
area = 3.14*radius*radius;
return area;
}
public double getPerimeter() //compute the perimeter of
circle
{
return 2*3.14*radius;
}
public String toString()
{
return "Circle : Center :"+ getX() +","+ getY() +" radius
:"+getRadius() ;
}
}
class Rectangle extends Point
{
private int length,width;
public Rectangle()
{
super(0,0);
length = 0;
width = 0;
}
public Rectangle(int x,int y,int length,int width)
{
super(x,y);
this.length = length;
this.width = width;
}
public int getLength()
{
return length;
}
public int getWidth()
{
return width;
}
public void setLength(int length)
{
this.length = length;
}
public double getArea() //compute the area of the square.
{
double area;
area = length * width;
return area;
}
public String toString()
{
return "Rectangle : Top left Point :"+ getX() +","+ getY() +"
length :"+getLength() +" width : "+getWidth();
}
}
class Cube extends Point
{
private Point p;
private int depth;
public Cube()
{
super(0,0);
depth = 0;
}
public Cube(int x,int y,int depth)// constructor
{
super(x,y);
this.depth = depth;
}
// set and get methods
public int getDepth()
{
return depth;
}
public Point getPoint()
{
return this.p;
}
public double getArea() //compute the area of the cube
{
double area;
area = 6*getDepth()*getDepth();
return area;
}
public double getVolume() //compute the volume of the cube
{
double vol;
vol = getDepth() * getDepth() * getDepth();
return vol;
}
public String toString()
{
return "Cube : Top left Point :"+ getX() +","+ getY() +" depth
:"+getDepth() ;
}
}
class GeometricTest
{
public static void main (String[] args)
{
Circle circle = new Circle(3,-1,6);
System.out.println(circle.toString());
System.out.println("Area of Circle = "+circle.getArea());
Rectangle r = new Rectangle(1,2,4,5);
System.out.println(r.toString());
System.out.println("Area of Rectangle = "+r.getArea());
Cube c = new Cube(4,5,2);
System.out.println(c.toString());
System.out.println("Area of cube = "+c.getArea());
System.out.println("Volume of cube = "+c.getVolume());
}
}
Output:
Success #stdin #stdout 0.05s 2184192KB
Circle : Center :3,-1 radius :6 Area of Circle = 113.03999999999999 Rectangle : Top left Point :1,2 length :4 width : 5 Area of Rectangle = 20.0 Cube : Top left Point :4,5 depth :2 Area of cube = 24.0 Volume of cube = 8.0
Do ask if any doubt. Please upvote.
Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...
Lab 1: InheritanceTest Write a program called InheritanceTest1.java to support an inheritance hierarchy for class Point–Square–Cube. Use Point as the superclass of the hierarchy. Specify the instance variables and methods for each class. The private data of Point should be the x-y coordinates, the private data of Square should be the sideLength, and the private data of Cube should be depth. Provide applicable accessor methods, mutator methods, toString() methods, area() method, and volume() method to all classes. Write a program...
Language is JAVA.
Clarification for the Shape class (highlighted):
The following requirements specify what fields you are expected
to implement in your Shape class;
- A private String color that specifies the color of the
shape
- A private boolean filled that specifies whether the shape is
filled
- A private date (java.util.date) field dateCreated that
specifies the date the shape was created Your Shape class will
provide the following constructors;
- A two-arg constructor that creates a shape
with...
What is the code for this in Java?
Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s ■ Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to...
JAVA: Quadrilateral Inheritance Hierarchy Write an inheritance hierarchy for classes Quadrilateral, Parallelogram, Rectangle, and Square. Use Quadrilateral as the superclass of the hierarchy. Create and use a Point class to represent the points in each shape. Make the hierarchy as deep as possible, i.e. more than two levels. Specify the instance variables and methods for each class. The private instance variables of Quadrilateral should be the x-y coordinate pairs for the four endpoints of the Quadrilateral. A program that instantiates...
java language
Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
Assignment Requirements
I have also attached a Class Diagram that describes the
hierarchy of the inheritance and interface behaviors . The link to
the PDF of the diagram is below
MotorVehical.pdf
Minimize File Preview
User Define Object Assignment:
Create a Intellij Project. The
Intellij project will contain three user defined
classes. The project will test two of the User Define Classes by
using the invoking each of their methods and printing the
results.
You are required to create three UML...
IN JAVA Design and code a class hierarchy that demonstrates your understanding of inheritance and polymorphism. Your hierarchy should contain at least 5 classes and one driver program that instantiates each type of object and runs multiple methods on those objects. Inheritance and Polymorphism must be apparent in the project. Please keep in mind that polymorphism was in chapter 37, so you will need to have read both chapters to understand what goes into this project. Bonus if you add...
Java assignment. There are five classes. You figure out the inheritance hierarchy. Animal, Dog, Brindle, Cat, Driver Note: Brindle is a kind of dog that has stripes The following classes will have a makeSound method that displays the kind of sound the animal makes. Animal, Dog, Cat In the Brindle class, you will have an instance variable noOfStripes One of the classes should have an instance variable to hold the name of the animal Name One of the classes should...
Java Create four classes: 1. An Animal class that acts as a superclass for Dog and Bird 2. A Bird class that is a descendant of Animal 3. A Dog class that is a descendant of Animal 4. A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: · one instance variable, a private String variable named name · a single constructor that takes one argument, a String, used to set...
IN JAVA For the following questions, “define a class” means the following: • Create an appropriately-named file containing the Java class definition, including the following: – A block comment describing the file (and hence the class), as always – Any instance variables, as required by the question – Accessor (getter) and mutator (setter) methods for any instance variables – Constructors as appropriate or as required by the question – A toString method that prints instances of the class informatively –...