-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllipse.java
More file actions
63 lines (55 loc) · 1.38 KB
/
Copy pathEllipse.java
File metadata and controls
63 lines (55 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package shapes;
import java.util.Scanner;
/**
* Filename: Ellipse.java
*
* @author Tina Hague
* @contributor Alexander Hamilton
*
* Last Updated: 26 Apr 2024
*/
public class Ellipse implements ShapeIO {
private double major = 0, minor = 0;
/**
* Creates a new ellipse object
*/
public Ellipse() {}
@Override
/**
* Asks the user for the dimensions and updates the instance variables
*
* @param scanner
*/
public void getSideLengths(Scanner scanner) {
System.out.println("What is the major axis length?");
major = scanner.nextDouble();
System.out.println("What is the minor axis length?");
minor = scanner.nextDouble();
}
@Override
/**
* Returns the area of the ellipse
*
* @return area
*/
public double getArea() {
return Math.PI * major * minor;
}
@Override
/**
* Returns the perimeter of the ellipse
*
* @return perimeter
*/
public double getPerimeter() {
return Math.PI * (major + minor) *
(3 * (Math.pow(major - minor, 2)
/ (Math.pow(major + minor, 2)
* (Math.sqrt(
-3 * (Math.pow(major - minor, 2)
/ Math.pow(major + minor, 2))
+ 4)
+ 10)))
+ 1);
}
}