Create a class called Square as described below:
• Fields: height, width • Methods: public double getHeight() public void setHeight(double h) public double getWidth () public void setWidth (double w) public double getArea ()
Hint: If I take your class and use it following would be the code and the output. Code Output double h, w, a; Square s1 = new Square(); s1.setHeight(3); s1.setWidth(4); h = s1.getHeight(); w = s1.getWidth(); a = s1.getArea(); System.out.println(“Height = ”+ h); System.out.println(“Width = ”+ w); System.out.println(“Area = ”+ a); Height = 3.0 Width = 4.0 Area = 12.0
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package JAVA_OBJECT_ORIENTED;
/**
*
* @author ABIR
*/
public class Square {
double height;
double width;
public void setHeight(double h){
height=h;
}
public double getHeight(){
return height;
}
public void setWidth (double w){
width=w;
}
public double getWidth (){
return width;
}
public double getArea (){
return height*width;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package JAVA_OBJECT_ORIENTED;
/**
*
* @author ABIR
*/
public class SquareTester {
public static void main(String[] args) {
double h, w, a;
Square s1 = new Square();
s1.setHeight(3);
s1.setWidth(4);
h = s1.getHeight();
w = s1.getWidth();
a = s1.getArea();
System.out.println("Height = "+ h);
System.out.println("Width = "+ w);
System.out.println("Area = "+ a);
}
}