IDNLearn.com makes it easy to find precise answers to your specific questions. Receive prompt and accurate responses to your questions from our community of knowledgeable professionals ready to assist you at any time.
Look at the following Polygon class:
public class Polygon
{
private int numSides;
public Polygon()
{
numSides = 0;
}
public void setNumSides(int sides)
{
numSides = sides;
}
public int getNumSides()
{
return numSides;
}
}
Write a public class named Triangle that is a subclass of the Polygon class. The Triangle class should have the following members:
a private int field named base
a private int field named height
a constructor that assigns 3 to the numSides field and assigns 0 to the base and height fields
a public void method named setBase that accepts an int argument. The argument's value should be assigned to the base field
a public void method named setHeight that accepts an int argument. The argument's value should be assigned to the height field
a public method named getBase that returns the value of the base field
a public method named getHeight that returns the value of the height field
a public method named getArea that returns the area of the triangle as a double.
Use the following formula to calculate the area: Area = (height * base) / 2.0
Sagot :
We value your presence here. Keep sharing knowledge and helping others find the answers they need. This community is the perfect place to learn together. Your questions deserve reliable answers. Thanks for visiting IDNLearn.com, and see you again soon for more helpful information.