You are on page 1of 4

NAME: JUNAID AHMED

CLASS: BSSE
ROLL NO: BSE-21S-099
SUBJECT: OOPS
SECTION: EVENING (2C)
COURSE INSRUCTOR: MISS SAIMA
SIPY
Task 1:

Task 2:

import java.util.Scanner;
public class Rectangle {

private int width = 0, length = 0;

    public Rectangle(int width, int length) {


        setWidth(width);
        setLength(length);
  }

    void setWidth(int width) {


        this.width = width;
  }

    void setLength(int length) {


        this.length = length;
  }
    int getWidth() {
        return this.width;
  }

    int getLength() {
        return this.length;
  }

    int getPerimeter() {
        return (2 * getWidth()) + (2 * getLength());
  }

    int getArea() {
        return (getWidth() * getLength());
  }

    boolean square() {
        return (getWidth() == getLength());
  }

    public static void main(String[] args) {


        Scanner obj = new Scanner(System.in);

        System.out.println("Enter width: ");


        int width = obj.nextInt();
        
        System.out.println("Enter length: ");
        int length = obj.nextInt();
        
        Rectangle rect = new Rectangle(width, length);
        System.out.printf("Area: " + rect.getArea());
        System.out.printf("\nPerimeter: " + rect.getPerimeter());

        if (rect.square()) {
            System.out.println("\nThis is a square.");
        } else {
            System.out.println("\nRectangle is a square : False");
    }
  }
}

You might also like