- Added abstract class _Shape.
	- Inherit _Rectangle from _Shape.
	- Parse width/height and use setters in constructors.
This commit is contained in:
HeshamTB 2020-09-26 03:55:36 +03:00
parent 6019f0fc41
commit 187f2cd313
Signed by: Hesham
GPG Key ID: 74876157D199B09E
2 changed files with 19 additions and 6 deletions

View File

@ -1,15 +1,17 @@
public class _Rectangle {
public class _Rectangle extends _Shape {
private double width;
private double height;
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){
this.width = w;
this.height = h;
setWidth(w);
setHeight(h);
}
public double getArea(){
@ -17,11 +19,13 @@ public class _Rectangle {
}
public void setWidth(double w){
this.width = w;
if (w != 0) this.width = w;
else this.width = 1;
}
public void setHeight(double h){
this.height = h;
if (h != 0) this.height = h;
else this.height = 1;
}
public double getWidth(){ return this.width; }

9
lab-02/src/_Shape.java Normal file
View 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; }
}