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

20XW57 JPL PS5

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

PSG COLLEGE OF TECHNOLOGY, COIMBATORE – 641 004

Department of Applied Mathematics and Computational Sciences


MSc Software Systems – Semester V
20XW57– Java Programming Lab
PROBLEM SHEET 5 – OOP
Completion Date: 06/08/2024

Note: Use Text Editors/IntelliJ IDEA/Apache NetBeans tools to develop, compile and execute the below
programs

1. Write a program to create a Room class, the attributes of this class is roomno, roomtype, and
roomarea. Implement the methods called setData and displayData to manipulate the data.
2. Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide
methods that calculate the rectangle’s perimeter and area. It has set and get methods for both
length and width. The set methods should verify that length and width are each floating-point
numbers larger than 0.0 and less than 20.0. Write a program to test class Rectangle.
3. Create a class named Player with the following private attributes.
String name, int age, String country
 Include appropriate getters and setters.
 Include a default constructor.
Include a 3-argument constructor. The order in which the parameters are passed is the name,
age, and country. Override the toString method to display the player details.
4. Create a class called Complex for performing arithmetic with complex numbers. Complex
numbers have the form
realPart + imaginaryPart * i, where i is √−1
Write a program to test your class. Use floating-point variables to represent the private data of
the class. Provide a constructor that enables an object of this class to be initialized when it’s
declared. Provide a no-argument constructor with default values in case no initializers are
provided. Provide public methods that perform the following operations:
a) Add two Complex numbers: The real parts are added together and the imaginary parts are
added together.
b) Subtract two Complex numbers: The real part of the right operand is subtracted from the
real part of the left operand, and the imaginary part of the right operand is subtracted from the
imaginary part of the left operand.
c) Print Complex numbers in the form (realPart, imaginaryPart).
5. Create a class named BloodData that includes fields that hold a blood type (the four blood
types are O, A, B, and AB) and an Rh factor (the factors are + and –). Create a default
constructor that sets the fields to O and +, and an overloaded constructor that requires values
for both fields. Include get and set methods for each field. Create a class named Patient that
includes an ID number, age, and BloodData. Provide a default constructor that sets the ID
number to 0, the age to 0, and the BloodData values to O and +. Create an overloaded
constructor that provides values for each field. Also provide get methods for each field. Create
an application that demonstrates that each method works correctly and test it.
6. Design a Stack class with the following methods as shown in the below UML class diagram.

7. A class called Customer, which models a customer in a transaction, is designed as shown in


the class diagram. A class called Invoice, which models an invoice for a particular customer
and composes an instance of Customer as its instance variable, is also shown. Design the
Customer and Invoice classes with following methods as shown in the below UML class
diagram. Also develop test driver class have main( ) method to test the below model.
8. Create a simplified e-commerce payment gateway using interfaces. Design an interface named
PaymentProcessor with methods for processing payments, validating credit cards, and
generating receipts. Implement this interface in classes representing different payment methods
(e.g., CreditCard, PayPal). Develop a program that simulates the payment process for online
purchases.
9. Create an abstract class named Element that holds properties of elements, including their
symbol, atomic number, and atomic weight. Include a constructor that requires values for all
three properties and a get method for each value. (For example, the symbol for carbon is C, its
atomic number is 6, and its atomic weight is 12.01. You can find these values by reading a
periodic table in a chemistry reference or by searching the Internet.) Also include an abstract
method named describeElement( ). Create two extended classes named MetalElement and
NonMetalElement. Each contains a describeElement( ) method that displays the details of the
element and a brief explanation of the properties of the element type. For example, metals are
good conductors of electricity, while nonmetals are poor conductors. Write an application
named ElementArray that creates and displays an array that holds at least two elements of each
type.
10. Create a package called General.
a. Create a one class in it called Person with appropriate properties and methods.
Create 2nd package called StudentDetail.
a. Create a class called Student which derives from Person class with appropriate properties
and method.
b. Create a class called Exam with its additional properties and methods which is derived
from Student class.
Create 3rd package called FacultyDetail.
Create a class called Faculty which derives from Person class with appropriate properties
and method.
Create 4th package called Test. Make a driver class to test Exam and Faculty class by creating
the objects of them.

You might also like