JAVA RECORD PROGRAM FOR AREA AND PERIMETER OF RECTANGLE

 // Java program to calculate  the area and perimeter of a rectangle using class concept

import java.util.*;

// Rectangle Class File

class Rectangle {

    // data members

    int length, width;

    // methods

    //constructor to create Object

    Rectangle(int length, int width) {

        this. length = length;

        this.width = width;

    }

    // prints the area of rectangle

    public void area() {

        int areaOfRectangle;

        areaOfRectangle = this.length * this.width;

        System.out.println("Area of rectangle with the given input is : " + areaOfRectangle);

    }

    // prints the perimeter of rectangle

    public void perimeter() {

        int  perimeterOfRectangle;

        perimeterOfRectangle = 2 * (this.length + this.width);

        System.out.println("Perimeter of rectangle with the given input is : " + perimeterOfRectangle);

    }

}

public class Main {

    public static void main(String args[]) {

        Rectangle rect_obj = new Rectangle(10,5);  // obect creation

        System.out.println("Length = " + rect_obj.length);

        System.out.println("Width = " + rect_obj.width);

        rect_obj.area(); // returns area of rectangle

        rect_obj.perimeter(); //returns perimeter of rectangle

    }

}

Comments

Popular posts from this blog

JAVA RECORD PROGRAM FOR FIBBONACCI SERIES

JAVA RECORD PROGRAM FOR MATRIX MULTIPLICATION