Computing area of rectangle by taking command line arguments
class Rectangle {
double length;
double breadth;
public Rectangle () {
length= 0 ;
breadth = 0;
}
public Rectangle(double l,double b) {
length = l;
breadth = b;
}
public void setLength(double l) {
length = l;
}
public void setBreadth(double b) {
breadth = b;
}
public double getLength () {
return length;
}
public double getBreadth () {
return breadth;
}
public double Area() {
return (length * breadth);
}
public double Perimeter() {
return (2*(length+breadth));
}
}
public class RectangleDemo2 {
public static void main(String[] args){
int n = args.length;
if(n != 2) {
System.out.println("expected two arguments");
return;
}
double pl = Double.parseDouble(args[0]);
double pb = Double.parseDouble(args[1]);
Rectangle rect = new Rectangle(pl,pb);
double area = rect.Area();
double l = rect.getLength();
double b = rect.getBreadth();
double temp = l*b;
System.out.println(area);
System.out.println(temp);
}
}
No comments:
Post a Comment