Improvfed constructors using this keyword. Filter input through setters.
This commit is contained in:
parent
7390d3d9f8
commit
6019f0fc41
@ -7,8 +7,7 @@ public class Circle extends _Point {
|
||||
* @param radius
|
||||
*/
|
||||
public Circle(double radius){
|
||||
super();
|
||||
setRadius(radius);
|
||||
this(radius, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ public class Cylinder extends Circle {
|
||||
public Cylinder(double r, double h){
|
||||
super(r);
|
||||
// Circle with location 0, 0 and radius r.
|
||||
this.height = h;
|
||||
setHeight(h);
|
||||
//now a cylinder with radius r and height h at 0,0
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ public class Cylinder extends Circle {
|
||||
*/
|
||||
public Cylinder(int x, int y,double r, double h){
|
||||
super(r, x, y); //a circle with radius r at x,y
|
||||
this.height = h;
|
||||
setHeight(h);
|
||||
//cylinder with radius r and height h at x,y
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,7 @@ 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(0,0, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,21 +21,21 @@ public class _Rectangle extends _Point {
|
||||
*/
|
||||
public _Rectangle(int x, int y, double w, double h){
|
||||
super(x, y);
|
||||
this.width = w;
|
||||
this.height = h;
|
||||
setHeight(h);
|
||||
setWidth(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* set height of rectangle
|
||||
* @param h height
|
||||
*/
|
||||
public void setHeight(double h){ this.height = h; }
|
||||
public void setHeight(double h){ if (h >= 0) this.height = h; else this.height = 0;}
|
||||
|
||||
/**
|
||||
* set width of rectangle
|
||||
* @param w width
|
||||
*/
|
||||
public void setWidth(double w){ this.width = w; }
|
||||
public void setWidth(double w){ if (w >= 0) this.width = w; else this.width = 0; }
|
||||
|
||||
/**
|
||||
* returns height
|
||||
|
Loading…
Reference in New Issue
Block a user