Pretend Quiz - Design of an Oval class Fill in Java code for a class for an oval
ID: 3689166 • Letter: P
Question
Pretend Quiz - Design of an Oval class Fill in Java code for a class for an oval. An oval (ellipse) has two semi- axes, called A and B in the picture. The area of an oval is Area = AB. Note that the class is a design for an Oval object. It itself does no input nor output. class oval private double A, B /semi-major axes publie ovalt covne a doueb l in paraneters // Constructor public oval Cone a colnye daunheb / fill in parameters // fill in code // Setters for A and B public void setA( double newA ) This a hen A /1 fill in code public void setB( double newB ) // fill in code // Getters for A and B public double getAC) /1 fi1l in code public double getBExplanation / Answer
TestOval.java
//Area of an Oval is 3.14*A*B
class Oval {
private double A, B;//semiAxix of an Oval
public double getA() {
return A;
}
public Oval(double A, double B) {
this.A = A;
this.B = B;//Constructor Oval with two Arguments
}
//setter and getter methods
public void setA(double A) {
this.A = A;//setting value
}
public double getB() {
return B;//getting values
}
public void setB(double B) {
this.B = B;
}
public String toString() {
String str = "Area of an Oval :";
System.out.println(str);
return str;
}
public double Area() {
double area = 3.14 * A * B;
System.out.println(area);
return area;
}
}
public class TestOval {
public static void main(String args[]) {//main method
Oval ovalX = new Oval(3.2, 3.4);//creating object and passing values
ovalX.toString();//calling toString method
ovalX.setA(9.23);
ovalX.Area();//callingArea method
}
}
output
Area of an Oval :
98.53948000000001
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.