Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SWE2005 Concepts of Object-Oriented Programming ELA FALL 2021-2022 Semester Lab Sessions - 10 Name: G.V.N.C.PRADYUMNA Reg No: 20MIS7088

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

SWE2005 Concepts of Object-Oriented Programming ELA FALL 2021-

2022 Semester

Lab Sessions - 10

Name: G.V.N.C.PRADYUMNA
Reg no: 20MIS7088

1. Implement the Shape hierarchy shown in Figure below. Each Two-


DimensionalShape should contain method getArea to calculate the area
of the two-dimensional shape. Each ThreeDimensionalShape should
have methods getArea and getVolume to calculate the surface area and
volume, respectively, of the three-dimensional shape. Create a program
that uses an array of Shape references to objects of each concrete class
in the hierarchy. The program should print a text description of the
object to which each array element refers. Also, in the loop that
processes all the shapes in the array, determine whether each shape is a
TwoDimensionalShape or a ThreeDimensionalShape. If it’s a
TwoDimensionalShape, display its area. If it’s a
ThreeDimensionalShape, display its area and volume.2. Write a Java
Program to implement array of objects.

CODE:
OUTPUT:
2. Create a class for Shutterbug’s Camera Store, which is having the digital
cameras to sale.

Class DigitalCamera:

 Add data fields for a brand, the number of megapixels in the resolution,
and price.
 Include a constructor that takes arguments for the brand and megapixels.
 If the megapixel parameter is greater than 16, the constructor sets it to
16.
 The sale price is set based on the resolution; any camera with 12
megapixels or fewer is $299, and all other cameras are $329.
 Also include a method that displays DigitalCamera details.

Write a class named TestDigitalCamera in which you instantiate at two


objects, prompt the user for values for the camera brand and number of
megapixels, and display all the values.

CODE:
OUTPUT:

3. Create a three different java classes Student, Marks and Grade with
necessary attributes and methods. Write a Test main class which gets the
following input and satisfies the given expected output conditions.

 Get student name, regno, noofsubjects and its marks.

Functional requirements of the classes:

 Student class should hold name, regno.


 If the student class have null values in name or regno, it should through
a NullPointerException
 Marks class should store all the subject marks and if any mark is
negative values or more than 100, it should through a user defined
exception message “Invalid Mark”
 Grade class should find the grade based on the following conditions
 If average of mark is >= 90 – A grade
 If average of mark is >= 80 and < 90 – B grade
 If average of mark is >= 70 and < 80 – C grade
 If average of mark is < 70 – F grade
 If the number of subject is less than 1, grade class should through an
ArithmeticException

Verify all the functional requirements with the Test class by creating the
instances and calling the respected methods.
CODE:
OUTPUT:

You might also like