Professional Documents
Culture Documents
ASSIGNMENT 1
QUESTION:
Create three shape classes - Rectangle, Square and Circle. Rectangle
has width and breadth, Square has side and Circle has radius as
member variables.
All the classes have getArea() method for implementation.
In the main method of FindSmallestShape, Create one object for
every class and compare their area's.
Print shape with smallest area and next smaller area.
Print shape with largest area and next larger area.
Print the areas of all these three shapes.
NAME: SIDHANT KAUSHIK
REG. NO: 20MIS0184
CODE:
import java.util.*;
class Rectangle
{
double breadth;
double width;
Rectangle(double breadth, double width)
{
this.breadth = breadth;
this.width = width;
}
double getArea()
{
return breadth * width;
}
}
class Square
{
double side;
Square(double side)
{
NAME: SIDHANT KAUSHIK
REG. NO: 20MIS0184
this.side = side;
}
double getArea()
{
return side * side;
}
}
class Circle
{
double radius;
Circle(double radius)
{
this.radius = radius;
}
double getArea()
{
return (22.0/7.0) * radius * radius;
}
}
System.out.println();
System.out.println();
System.out.println("Rectangle Area : " + r.getArea());
System.out.println("Square Area : " + s.getArea());
System.out.println("Circle Area : " + c.getArea());
System.out.println();
}
}
NAME: SIDHANT KAUSHIK
REG. NO: 20MIS0184
SNAPSHOT OF NOTEPAD:
NAME: SIDHANT KAUSHIK
REG. NO: 20MIS0184
NAME: SIDHANT KAUSHIK
REG. NO: 20MIS0184
NAME: SIDHANT KAUSHIK
REG. NO: 20MIS0184
SNAPSHOT OF OUTPUT: