Find the area of Rectangle(LinkList)

Find the area of Rectangle(LinkList)

Previous Home Next

 

Following program for find the area and Circumference of a rectangle using the LinkList.

 

 

//First program in LinkList

/*
 * Save as a RectangleLink.java
 * Program for create a LinkList between RectangleLink.java and RectangleDraw.java
 * In LinkList, the parameter declear in RectangleLink.java may be used in RectangleDraw.java
 */
package r4r.co.in;

public class RectangleLink {

    public static void main(String []args){

    //Random Length and Breath generated
    float length = (float) (100.00 * Math.random());
    float breath= (float) (100.00* Math.random());

    //General show the value of parameter.
    System.out.println("Generated value: Lengteh "+length+" && Breath: " +breath);

  //Create the RectangleDraw and passing the value.
    RectangleDraw rectangleDraw= new RectangleDraw(length,breath);
  //Dispaly the RectangleDraw
    rectangleDraw.show();
    }
}



//Second program in LinkList

/*
 * Save as a RectangleDraw.java
 * Program that take the value from the RectangleLink.java
 */
package r4r.co.in;

class RectangleDraw {

    float area;
    float Circumference;

    RectangleDraw(float  length, float  breath) {

        //Length and Breath parameter from the RectangleLink.java
        area = length * breath;
        Circumference = 2 * (length + breath);
    }

    void show() {

        System.out.println("Area of Rectangle:" + area);
        System.out.println("Circumference of a rectangle:" + Circumference);
    }
}

Generated value: Lengteh 77.41628 && Breath: 67.967094
Area of Rectangle:5261.76
Circumference of a rectangle:290.76675
Previous Home Next