AP Midsem Set1
AP Midsem Set1
QUESTION-1: Create a class Earthquake which has 2 attributes: a name (String), and
intensity (floating point number). In the Main class, first take in a string and a floating
point number as user input (you can assume valid inputs). If the floating point number is
NOT in the range 2.0 to 8.0 (both inclusive in the range), then you have to throw a
custom (user-defined) exception and handle it suitably. If it’s in the range, you have to
create an object of the Earthquake class initialized with the values taken as input, and
print the object using the System.out.println method such that its attributes get
displayed. (40% Weightage)
TEST CASE-1:
TEST CASE-2:
QUESTION-2: You will be designing an OOPS based system for shapes and perform
basic geometric operations on them. Make sure you use OOPS concepts such as
encapsulation, inheritance, polymorphism and more. Consider a two-dimensional
cartesian plane, where each point is represented using two coordinates (x, y). We will
consider the following types of shapes -
Each shape has an area and a perimeter associated with it which is calculated
differently for each shape (you can take pi = 3.14) -
Note: you can assume that input points for Triangle and Quadrilateral are always given
in clockwise direction (look at the test case)
Note: You are free to use helper functions as you see fit, on top of the mandatory
requirements. It is advisable to think of helper functions as they will drastically reduce
the complexity of your code.
1. Circle
- boolean checkIntersection(Circle circle): should return true or false
depending on whether two circles intersect or not (assume circles just
touching to also be intersecting)
2. Triangle
- String getType(): should return the type of triangle as ‘equilateral (a=b=c)’,
‘isosceles (two sides equal)’ or ‘scalene (sides are not equal)’
3. Quadrilateral
- String getType(): should return the type of the quadrilateral as either
‘parallelogram’ or ‘rhombus’
Note: You have to write the code from scratch - you can either take values as input or
hard code them. An example for your reference is given below. (60% Weightage)
TEST CASE
(you have to create two circles, one triangle and one quadrilateral)
4 // number of elements in shapes array
circle // type of shape
0 0 1 // (x, y, radius) of circle
circle // type of shape
2 0 2 // (x, y, radius) of circle
triangle // type of shape
0 0 0 4 3 0 // (x1, y1, x2, y2, x3, y3) in clockwise order
quadrilateral // type of shape
0 0 1 0 1 1 0 1 // (x1, y1, x2, y2, x3, y3, x4, y4) in clockwise order
12 // perimeter of triangle
6 // area of triangle
4 // perimeter of quadrilateral
1 // area of quadrilateral
true