Use 'super' constructors and parse negative circle radius.
This commit is contained in:
parent
4a8354a474
commit
7390d3d9f8
@ -7,8 +7,8 @@ public class Circle extends _Point {
|
||||
* @param radius
|
||||
*/
|
||||
public Circle(double radius){
|
||||
this.radius = radius;
|
||||
this.setLocation(0, 0);
|
||||
super();
|
||||
setRadius(radius);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -18,15 +18,20 @@ public class Circle extends _Point {
|
||||
* @param y
|
||||
*/
|
||||
public Circle(double radius, int x, int y){
|
||||
this.radius = radius;
|
||||
this.setLocation(x, y);
|
||||
super(x, y);
|
||||
setRadius(radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* set radius
|
||||
* @param radius
|
||||
*/
|
||||
public void setRadius(double radius) { this.radius = radius; }
|
||||
public void setRadius(double radius) {
|
||||
//default to unit circle if bad radius is given.
|
||||
//Maybe take abs(r) to negate negative radius.
|
||||
if (radius < 0) { this.radius = 1; }
|
||||
else this.radius = radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* get radius
|
||||
|
@ -8,7 +8,7 @@ public class Cylinder extends Circle {
|
||||
* @param h height
|
||||
*/
|
||||
public Cylinder(double r, double h){
|
||||
super(r);//Recommended by IDE. Invokes Circle(double radius).
|
||||
super(r);
|
||||
// Circle with location 0, 0 and radius r.
|
||||
this.height = h;
|
||||
//now a cylinder with radius r and height h at 0,0
|
||||
|
@ -9,9 +9,9 @@ public class _Rectangle extends _Point {
|
||||
* @param height height of rectangle
|
||||
*/
|
||||
public _Rectangle(double width, double height){
|
||||
super();// This might be useless.
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
this.setLocation(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -22,9 +22,9 @@ public class _Rectangle extends _Point {
|
||||
* @param h height of rectangle
|
||||
*/
|
||||
public _Rectangle(int x, int y, double w, double h){
|
||||
super(x, y);
|
||||
this.width = w;
|
||||
this.height = h;
|
||||
this.setLocation(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user