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
|
* @param radius
|
||||||
*/
|
*/
|
||||||
public Circle(double radius){
|
public Circle(double radius){
|
||||||
this.radius = radius;
|
super();
|
||||||
this.setLocation(0, 0);
|
setRadius(radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,15 +18,20 @@ public class Circle extends _Point {
|
|||||||
* @param y
|
* @param y
|
||||||
*/
|
*/
|
||||||
public Circle(double radius, int x, int y){
|
public Circle(double radius, int x, int y){
|
||||||
this.radius = radius;
|
super(x, y);
|
||||||
this.setLocation(x, y);
|
setRadius(radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set radius
|
* set radius
|
||||||
* @param 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
|
* get radius
|
||||||
|
@ -8,7 +8,7 @@ public class Cylinder extends Circle {
|
|||||||
* @param h height
|
* @param h height
|
||||||
*/
|
*/
|
||||||
public Cylinder(double r, double h){
|
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.
|
// Circle with location 0, 0 and radius r.
|
||||||
this.height = h;
|
this.height = h;
|
||||||
//now a cylinder with radius r and height h at 0,0
|
//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
|
* @param height height of rectangle
|
||||||
*/
|
*/
|
||||||
public _Rectangle(double width, double height){
|
public _Rectangle(double width, double height){
|
||||||
|
super();// This might be useless.
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.setLocation(0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,9 +22,9 @@ public class _Rectangle extends _Point {
|
|||||||
* @param h height of rectangle
|
* @param h height of rectangle
|
||||||
*/
|
*/
|
||||||
public _Rectangle(int x, int y, double w, double h){
|
public _Rectangle(int x, int y, double w, double h){
|
||||||
|
super(x, y);
|
||||||
this.width = w;
|
this.width = w;
|
||||||
this.height = h;
|
this.height = h;
|
||||||
this.setLocation(x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user