20XW57 JPL PS5
20XW57 JPL PS5
20XW57 JPL PS5
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.