lab-02:
- Added abstract class _Shape. - Inherit _Rectangle from _Shape. - Parse width/height and use setters in constructors.
This commit is contained in:
parent
6019f0fc41
commit
187f2cd313
@ -1,15 +1,17 @@
|
|||||||
public class _Rectangle {
|
public class _Rectangle extends _Shape {
|
||||||
|
|
||||||
private double width;
|
private double width;
|
||||||
private double height;
|
private double height;
|
||||||
|
|
||||||
public _Rectangle(double w){
|
public _Rectangle(double w){
|
||||||
this.width = w;
|
//Since only width or height is given, assume square.
|
||||||
|
setWidth(w);
|
||||||
|
setHeight(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _Rectangle(double w, double h){
|
public _Rectangle(double w, double h){
|
||||||
this.width = w;
|
setWidth(w);
|
||||||
this.height = h;
|
setHeight(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getArea(){
|
public double getArea(){
|
||||||
@ -17,11 +19,13 @@ public class _Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setWidth(double w){
|
public void setWidth(double w){
|
||||||
this.width = w;
|
if (w != 0) this.width = w;
|
||||||
|
else this.width = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeight(double h){
|
public void setHeight(double h){
|
||||||
this.height = h;
|
if (h != 0) this.height = h;
|
||||||
|
else this.height = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getWidth(){ return this.width; }
|
public double getWidth(){ return this.width; }
|
||||||
|
9
lab-02/src/_Shape.java
Normal file
9
lab-02/src/_Shape.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
public abstract class _Shape {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public void setName(String name) { this.name = name; }
|
||||||
|
|
||||||
|
public String getName(){ return name; }
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user