Create a class Rectangle.The class has attributes length and width,each of which defaults to 1.It has methods that calculate the premiter and the area of the rectangle.It has set and get methods for both length and width.The set method should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0 .(Fille must be save as : Assignment3.java)
import javax.swing.JOptionPane;
class SetValue
{
float l,w,a;
SetValue()
{
w=1;
l=1;
}
void set()
{
String s;
s=JOptionPane.showInputDialog("Length = ");
a=Float.parseFloat(s);
if(a<20&&a>0)
l=a;
else
System.out.println("Length is out of rang.");
s=JOptionPane.showInputDialog("Width = ");
a=Float.parseFloat(s);
if(a<20&&a>0)
w=a;
else
System.out.println("Width is out of rang.");
}
void get()
{
System.out.println("Premiter : "+2*(w+l));
System.out.println("Area : "+l*w);
}
}
class Assignment03
{
public static void main(String args[])
{
SetValue b=new SetValue();
b.set();
b.get();
System.exit(0);
}
}
////////////////////////////////////////////
Copy & paste this code in your TC & run, then you will get output.......
If you have any problem please comment below.........
Copy & paste this code in your TC & run, then you will get output.......
If you have any problem please comment below.........