Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 13, 2019 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0ryant/25cf8679ed62491d5bbcb173a214d8cd to your computer and use it in GitHub Desktop.
Save 0ryant/25cf8679ed62491d5bbcb173a214d8cd to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Classes; Wall Area
public class Wall {
// Params
private double width;
private double height;
// Constructors
public Wall() {
}
public Wall(double width,double height){
this.width=width;
this.height=height;
if (width<0){
this.width=0;
}
if (height<0){
this.height=0;
}
}
// Getters
public double getWidth() {
return width;
}
public double getHeight() {
return height;
}
// Setters
public void setWidth(double width) {
if (width<0){
this.width=0;
} else {
this.width = width;
}
}
public void setHeight(double height) {
if (height<0){
this.height=0;
} else {
this.height = height;
}
}
// Extra Methods
public double getArea(){
return (this.height*this.width);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment