-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllipse.java
More file actions
40 lines (28 loc) · 888 Bytes
/
Ellipse.java
File metadata and controls
40 lines (28 loc) · 888 Bytes
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
public class Ellipse extends Circle{
private double a;
private double b;
public Ellipse(String name, double r, double a, double b){
super(name, r);
this.a = a;
this.b = b;
}
public double perimeter(){
double p;
if(a==b && b==radius){
p = super.perimeter();
//return p; u can return individually like dis
}else{
//return Math.PI*(Math.sqrt(2*(Math.pow(a,2)+(Math.pow(b,2))- (Math.pow((a-b),2)/2);
p = Math.PI*Math.sqrt(2*(a*a+b*b)- Math.pow(a-b,2)/2);
//return p; and individually like dis
}
return p; //but more sensible to return just once outside ur if statements
//return Math.PI*Math.sqrt(2*(a*a+b*b)- Math.pow(a-b,2)/2);
}
public double area(){
return Math.PI*a*b;
}
public String toString(){
return super.toString();
}
}