1 answer

Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

Question:

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.

y for each class for each class. Point Rectangle Circle Cube Figure: Shape inheritance hierarchy

y for each class for each class. Point Rectangle Circle Cube Figure: Shape inheritance hierarchy

Answers

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.

.

Similar Solved Questions

1 answer
If 43.5 mol of an ideal gas occupies 58.5 L at 65.00 ∘C, what is the...
If 43.5 mol of an ideal gas occupies 58.5 L at 65.00 ∘C, what is the pressure of the gas?...
1 answer
How the health service department can stick to its historic mission of serving those without insurance...
How the health service department can stick to its historic mission of serving those without insurance and/or those that are historically underserved....
1 answer
Attempt 1 Question 7 of 9 > Butanone undergoes a nucleophilic addition with a Grignard reagent...
Attempt 1 Question 7 of 9 > Butanone undergoes a nucleophilic addition with a Grignard reagent made from 1-bromopropane and magnesium metal in THF solution. The alkoxide formed from the nucleophilic addition is then conveted into the final product by the careful addition of dilute acid. Complete ...
1 answer
Oncept and properties of the and to practice simple logarithmic Correct Notice that his set of...
oncept and properties of the and to practice simple logarithmic Correct Notice that his set of problems will help you cept of logarithms, so that you may he pH scale of acidity, which is a of H3O]. Unless otherwise nction has a base of 10. Here are log(10-22 log(10-1) -1 log(10) 0 log(10)1 log(102)2...
1 answer
Discuss K-selected and R-selected species. Provide a comparison of the two types of organisms in the...
discuss K-selected and R-selected species. Provide a comparison of the two types of organisms in the form of a table or bulleted summary. Include key characteristics that differentiate the two and provide a couple of examples of each....
1 answer
Question 2 1 pts You're offered an investment that will pay you 5,317 in one year,...
Question 2 1 pts You're offered an investment that will pay you 5,317 in one year, 9,286 in two years, and 3,500 in 3 years. If you require a return of 4%, what is this investment worth to you? Question 3 1 pts What is the future value of a stream of payments in the amount of 1,514 to be receive...
1 answer
If you were the manager of a large firm that is unable to achieve economies of...
if you were the manager of a large firm that is unable to achieve economies of scale, would you recommend that the firm should cease operations and close? Why or why not?...
1 answer
1. A 480 V (rms) source supplies power to two loads connected in parallel. The first...
1. A 480 V (rms) source supplies power to two loads connected in parallel. The first load draws 80 kW and 30 kVAR. The second load draws 100 kVA at a power factor of 0.6 lagging. a) Draw the power triangle for the first load and determine its power factor; b) Determine the current (both magnitude an...
1 answer
111. Of the 100 bikes at a bike shop, there are 30 blue bikes and 24...
111. Of the 100 bikes at a bike shop, there are 30 blue bikes and 24 mountain bikes. Of the 30 blue bikes, 8 are mountain bikes. If a bike is selected at random from this shop, what is the probability that both of the following are true: the bike is not blue and is not a mountain bike? I A. 27 50 7 ...
1 answer
Suppose you win a 100 million lottery and you can choose the following two payment options:...
Suppose you win a 100 million lottery and you can choose the following two payment options: 1) receive 25 equal payments of $4,000,000- one payment today and one payment at the end of each of next 24 years. 2) one time lump sum payment of $59 million. Question 1: If you can invest your proceeds and ...
1 answer
The same stock of money can count as () to a bank and () to an...
The same stock of money can count as () to a bank and () to an individual. A. deposits; reserves B. reserves; deposits C. money; reserves D. deposits; money...
1 answer
4) A tube with one open end and one closed end has á resonant frequency of...
4) A tube with one open end and one closed end has á resonant frequency of 71.0 Hz. Find the length of the tube- and find the first three overtones. Use 343 m/s for the speed of sound....
1 answer
I need this solution using C++ Write a report over programming. Include numbers on your submission...
I need this solution using C++ Write a report over programming. Include numbers on your submission to identify which part of the assignment you are taking care of. 1. (10 points) Include a title that explains in a sentence what you learned or noticed. 2. (70 points) Include your code for the prog...
1 answer
Hi! how did they get the price offer and demand curves for perfect subsititutes? i dont...
hi! how did they get the price offer and demand curves for perfect subsititutes? i dont get how they got these curves? Sereenshot 2015-10-30 at 20.26.46 - Q Search Examples: Perfect Substitutes The demand function for good 1 is m/P1 any number between 0 and m/pi when P1 < P2 when P1 = P2; whe...
1 answer
O False 4 pts Question 7 In thinking of increasing your nonverbal competence (4.3) what are...
O False 4 pts Question 7 In thinking of increasing your nonverbal competence (4.3) what are two ways you can improve in either giving or receiving non-verbal messages. Give an example for each. HTML Editore A 2 E BI U A - EBO . I E V G 1 1 1 x'x, O T 12pt Paragraph In thinking of increasing the ...
1 answer
What are the key differences between a forward and a futures contract?
What are the key differences between a forward and a futures contract?...
1 answer
Define "Minute Clinic" - what types of diagnoses/symptoms are treated in a Minute Clinic? one paragraph...
Define "Minute Clinic" - what types of diagnoses/symptoms are treated in a Minute Clinic? one paragraph minimum...
1 answer
3. (40 pts.) A vertical cylinder fitted with a frictionless piston contains 10 kg of Water...
3. (40 pts.) A vertical cylinder fitted with a frictionless piston contains 10 kg of Water at 0.1 MPa and x = 40%. The system is heated by an external source at 227°C until the specific volume reaches 2.24 m3/kg. The weight of the piston is such that it takes a water pressure of 0.2 MPa for it t...