Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make a class Shape with num_Sides as an integer with method void getSides()that

ID: 3679996 • Letter: M

Question

Make a class Shape with num_Sides as an integer with method void getSides()that will display the number of sides and void setSides(int s)that will set the number of sides. It will have a class called Rectangle that inherits from Shape. It has int length and int width and it has constructor (no argument) that sets length to 10 and width to 15. It has method showDimensions() as a void that will display the length and width. It will have a getArea() as a void that will display the area of the rectangle. Create a tester file that will create an object r from the Rectangle. It will call the getSides() method from parent class and will display the number of sides.It will call the showDimensions() method and getArea()method.

Explanation / Answer

public class Shape
{
int num_Sides;
public void getSides()
{
System.out.println(num_Sides);
}
public void setSides(int s)
{
num_Sides=s;
}
}
public class Rectangle extends Shapes
{
int length;
int width;
int area;
public Rectangle()
{
length=10;
width=15;
}
public void showDimensions()
{
System.out.println(length);
System.out.println(width);
}
public void getArea()
{
area=length*width;
System.out.println(area);
}
}
public class Test
{
public static void main(String args[])
{
Rectangle r =new Rectangle();
r.setSides(4);
r.getSides();
r.showDimensions();
r.getArea();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote