0% found this document useful (0 votes)
6 views

AP Midsem Set1

The document describes two programming questions related to object-oriented programming in Java. The first question involves creating Earthquake class and handling invalid input. The second question involves designing a system for geometric shapes using OOP concepts like inheritance and polymorphism. The shapes include Circle, Triangle and Quadrilateral and require calculating their areas and perimeters. Additional shape-specific functions are also defined.

Uploaded by

Nandini Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

AP Midsem Set1

The document describes two programming questions related to object-oriented programming in Java. The first question involves creating Earthquake class and handling invalid input. The second question involves designing a system for geometric shapes using OOP concepts like inheritance and polymorphism. The shapes include Circle, Triangle and Quadrilateral and require calculating their areas and perimeters. Additional shape-specific functions are also defined.

Uploaded by

Nandini Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ADVANCE PROGRAMMING (CSE201)

MID SEM EXAM


Monsoon 2022

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 -

- A circle which has a centre coordinate (x, y) and radius value


- A triangle which has three points representing three vertices
- A quadrilateral which is represented using four points representing four vertices

Each shape has an area and a perimeter associated with it which is calculated
differently for each shape (you can take pi = 3.14) -

Shape Perimeter Area

Circle 2*pi*radius pi*radius*radius

Triangle sum of side lengths heron’s formula

Quadrilateral sum of side lengths divide into two triangles


and apply heron’s formula

Heron’s formula => Area of triangle = 𝑠𝑞𝑟𝑡(𝑠 * (𝑠 − 𝑎) * (𝑠 − 𝑏) * (𝑠 − 𝑐))


where 𝑠 = (𝑎 + 𝑏 + 𝑐)/2 and a, b, c represent side lengths of the triangle

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.

The class hierarchy can roughly be visualised as follows -


Along with this you also have to implement shape-specific functions as mentioned
below -

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

<print area and perimeter of circle-2>

12.56 // perimeter of circle-2


12.56 // area of circle-2

<print area and perimeter of triangle>

12 // perimeter of triangle
6 // area of triangle

<print area and perimeter of quadrilateral>

4 // perimeter of quadrilateral
1 // area of quadrilateral

<check intersection of circle-1 and circle-2>

true

<use getType() function to print the type of triangle and quadrilateral>

scalene // for triangle


rhombus // for quadrilateral

You might also like