In: Computer Science
This is an intro to java question. Please post with pseudocode and java code.
Problem should be completed using repetition statements like
while and selection statements.
Geometry (10 points) Make API (API design) Java is an extensible
language, which means you can expand the programming language with
new functionality by adding new classes. You are tasked to
implement a Geometry class for Java that includes the following API
(Application Programming Interface): Geometry Method API: Modifier
and Type Method and Description static double
getAreaRectangle(double width, double length) Returns the area of a
rectangle, area = length * width static double getAreaCircle(double
radius) Returns the area of a circle, area = ?(radius 2 ) static
double getAreaTriangle(double base, double height) Returns the area
of a triangle, area = ½(base * height) static double
getPerimeterRectangle(double width, double length) Returns the
perimeter of a Rectangle, perimeter = 2(length + width) static
double getPerimeterCircle(double radius) Returns the perimeter of a
Circle, perimeter = 2?(radius) static double
getPerimeterTriangle(double side1, double side2, double side3)
Returns the perimeter of a triangle, perimeter = s1 + s2 + s3 Facts
● Java Math class contains an approximation for PI, i.e. Math.PI ●
Your Geometry class implementation should not have a main method. ●
NO Scanner for input & NO System.out for output! Input The
Geometry class will be accessed by an external Java Application
within Autolab. This Java app will send data in as arguments into
each of the methods parameters. Output The Geometry class should
return the correct data calculations back to the invoking client
code
Sample Method Calls
getAreaRectangle(1,1);
getAreaCircle(1);
getAreaTriangle(1,1);
getPerimeterRectangle(1,1);
getPerimeterCircle(1);
getPerimeterTriangle(1,1,1);
Sample Method Returns
1.0
3.141592653589793
0.5
4.0
6.283185307179586
3.0
CODE
class Geometry {
static double getAreaRectangle(double width, double length) {
return width * length;
}
static double getAreaCircle(double radius) {
return Math.PI * radius * radius;
}
static double getAreaTriangle(double base, double height) {
return 0.5 * base * height;
}
static double getPerimeterRectangle(double width, double length) {
return 2 * (width + length);
}
static double getPerimeterCircle(double radius) {
return 2 * Math.PI * radius;
}
static double getPerimeterTriangle(double side1, double side2, double side3) {
return (side1 + side2 + side3);
}
}
public class Main {
public static void main(String[] args) {
System.out.println(Geometry.getAreaRectangle(1,1));
System.out.println(Geometry.getAreaCircle(1));
System.out.println(Geometry.getAreaTriangle(1,1));
System.out.println(Geometry.getPerimeterRectangle(1,1));
System.out.println(Geometry.getPerimeterCircle(1));
System.out.println(Geometry.getPerimeterTriangle(1,1,1));
}
}