Aim/Overview of The Practical:: Worksheet Questions

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.

Aim/Overview of the practical:


To write programs for the questions given below.

2. Task to be done:

Worksheet Questions:

We have to calculate the area of a rectangle, a square and a circle. Create an interface 'Shape' with
three abstract methods namely 'RectangleArea' taking two parameters, 'SquareArea' and 'CircleArea'
taking one parameter each. The parameters of 'RectangleArea' are its length and breadth, that of
'SquareArea' is its side and that of 'CircleArea' is its radius. Now create another class 'Area' containing
all the three methods 'RectangleArea', 'SquareArea' and 'CircleArea' for printing the area of rectangle,
square and circle respectively. Create an object of class 'Area' and call all the three methods.

3. Code for experiment/practical:

Code for 1st Question:

package com.company;

import java.util.Scanner;

interface shape { public void rectangle(int length,int breadth);

public void square(int side);

public void circle(int radius);

class area implements shape

@Override public void rectangle(int length, int breadth)

int area=length*breadth;

System.out.println(area);
}

public void square(int side)

int area=side*side;

System.out.println(area);

public void circle(int radius)

double pi=3.14; double area=pi*radius*radius; System.out.println(area);

public class first { public static void main(String[] args)

area obj1 =new area();

Scanner in=new Scanner(System.in);

System.out.println("Enter the length of rectangle");

int length=in.nextInt();

System.out.println("Enter the breadth of rectangle");

int breadth=in.nextInt();

obj1.rectangle(length,breadth);

System.out.println("Enter the Side of square");

int square=in.nextInt();

obj1.square(square);

System.out.println("Enter the radius of the circle");

int circle= in.nextInt();

obj1.circle(circle);
}

4. Result/Output/Writing Summary:

Output of 1st Program:

Enter the length of rectangle

Enter the breadth of rectangle

Enter the Side of square

Enter the radius of the circle

28.259999999999998

Process finished with exit code 0

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and Performance 5
(Pre Lab Quiz)
2. Worksheet 10
3. Post Lab Quiz 5

You might also like