The design for class and inheritance 1. Inheritance progrmming (1).Create class Point, with two private instance variables x and y that representd for the coodinates of a point. Provide constructor for initializing two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coodinates. (2). Create class Circle,it inheritance from Point. Provide a integer private redius instance variable. Provide constructor to initialize the center coodinates and redius for a circle,.In the constructor it must calls its supperclass constructor by using super(x,y); Provide set and get for redius instance variable. Provide two methods for calculating its area and perimeter. Provide toString method to return a formatted string for a circle features.In the method, it must calls its supperclass toString method by using super.toString(). (3)Similar to the above class Circle definitionto,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 volumn for a Cube. (5)Design a test-class to test above four classes functionality. It creates four objects for these classes and call the corresponding methods to test entire functionality for each class. Complete the following code: …… class GeometricTest { public static void main (String[] args) { System.out.println(new Point(1,1)); Circle circle = new Circle(3,-1,6); System.out.println(circle.toString()); System.out.printf("Area of Circle = %.2f\n",circle.getArea()); Rectangle r = new Rectangle(1,2,4,5); System.out.println(r.toString()); System.out.printf("Area of Rectangle = %.2f\n",r.getArea()); Cube c = new Cube(4,5,2); System.out.println(c.toString()); System.out.printf("Area of cube = %.2f\n",c.getArea()); System.out.printf("Volume of cube = %.2f\n",c.getVolume()); } } The running output: Point: 1,1 Circle : Center:3,-1 radius:6 Area of Circle = 113.04 Rectangle : Top left 1,2 length:4 width:5 Area of Rectangle = 20.00 Cube : Top left Point:4,5 depth :2 Area of cube = 24.00 Volume of cube = 8.00
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
5.The design for class and inheritance
- 1. Inheritance progrmming
(1).Create class Point, with two private instance variables x and y that representd for the coodinates of a point.
Provide constructor for initializing two instance variables.
Provide set and get methods for each instance variable,
Provide toString method to return formatted string for a point coodinates.
(2). Create class Circle,it inheritance from Point.
Provide a integer private redius instance variable.
Provide constructor to initialize the center coodinates and redius for a circle,.In the constructor it must calls its supperclass constructor by using super(x,y);
Provide set and get for redius instance variable.
Provide two methods for calculating its area and perimeter.
Provide toString method to return a formatted string for a circle features.In the method, it must calls its supperclass toString method by using super.toString().
(3)Similar to the above class Circle definitionto,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 volumn for a Cube.
(5)Design a test-class to test above four classes functionality.
It creates four objects for these classes and call the corresponding methods to test entire functionality for each class.
Complete the following code:
……
class GeometricTest
{
public static void main (String[] args)
{
System.out.println(new Point(1,1));
Circle circle = new Circle(3,-1,6);
System.out.println(circle.toString());
System.out.printf("Area of Circle = %.2f\n",circle.getArea());
Rectangle r = new Rectangle(1,2,4,5);
System.out.println(r.toString());
System.out.printf("Area of Rectangle = %.2f\n",r.getArea());
Cube c = new Cube(4,5,2);
System.out.println(c.toString());
System.out.printf("Area of cube = %.2f\n",c.getArea());
System.out.printf("Volume of cube = %.2f\n",c.getVolume());
}
}
The running output:
Point: 1,1
Circle : Center:3,-1 radius:6
Area of Circle = 113.04
Rectangle : Top left 1,2 length:4 width:5
Area of Rectangle = 20.00
Cube : Top left Point:4,5 depth :2
Area of cube = 24.00
Volume of cube = 8.00
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)