Assignment-2.
1 for Generics and Collections (Part 1)
Subject: CSW2 (CSE 3141)
Session: Jan to May 2025
Branch: CSE
Section: All
Course Outcomes: CO1
Learning Levels: Remembering (L1), Understanding (L2), Application (L3), and Analysis (L4).
Q no. Questions Learning
Levels
Q1. Write a program to create a Student class with the following attributes: name, L1, L2
rollNumber, and age. The rollNumber should be designed to accept both integers and
strings. Additionally, implement a driver class to create Student objects and invoke
relevant methods.
Q2. Write a program to create a Book class with the following member variables: bookId, L2, L3
bookName, and price. Implement the appropriate constructor and methods for this
class.
Additionally, create a driver class to:
i. Instantiate two Book objects.
ii. Compare the books based on their price.
iii. Print the details of both books.
Note: Override the toString() and equals() methods.
Q3. Write a program to create a Car class with the following member variables: model, L3, L4
color, and speed. Implement the appropriate constructor and methods for this class.
Additionally, create a driver class to:
i. Instantiate two Car objects.
ii. Compare the cars based on their speed.
iii. Print the details of the car with the greater speed.
Note: Implement the Comparable interface and override the compareTo() method.
Q4. Write a program to create a Student class with member variables name, rollNumber, L2, L3
and totalMark. The program should allow the creation of an array of Student objects
and implement a linear search to find a specific student in the array. Additionally, the
Student class should implement the Comparable interface by overriding the
compareTo() method to facilitate comparisons between student objects.
Q5. Write a program to create a Student class with member variables name, rollNumber, L3, L4
and totalMark. The program should create an array of Student objects and sort them
using the Bubble Sort algorithm based on their roll numbers.
Note: Implement the Comparable interface and override the compareTo() method for
comparison.
Q6. Write a program to create an Animal class with member variables name, color, and L2, L3
type (indicating whether the animal is a pet or wild). Override the hashCode() method
to generate a unique identifier for each object. Then, create multiple Animal objects
and print their hash codes.
Q7. Write a program to create a Student class with member variables name, rollNo, and L3, L4
age. The program should allow the creation of an array of Student objects and
implement sorting based on rollNo and age in the driver class. The sorted student
arrays should be printed separately. Additionally, the program should utilize the
Comparator interface by overriding the compare() method to enable custom
comparisons for sorting.
-END-