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

SWE2005 Assignment Questions

Uploaded by

Nitya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SWE2005 Assignment Questions

Uploaded by

Nitya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Develop a Java program for a simple animal sound application that uses polymorphism to produce different
sounds for different types of animals. Implement an interface Animal with methods makeSound() and
describe(). The describe() method should return a description of the animal (use a default implementation for
describe()). Create classes Dog, Cat, and Cow that implement the Animal interface. Each class should
override the makeSound() method to display the sound the animal makes, and override the describe() method
to return a description specific to that animal (e.g., for Dog: "This is a dog", for Cat: "This is a cat", for Cow:
"This is a cow"). Use polymorphism to iterate through an array, invoke makeSound() to produce the animal's
sound, and describe() to display the description of each animal.
2. A library management system needs to keep track of different types of media items. Create an interface
`MediaItem` which has an abstract method `calculateLateFee()` and a default method `displayLateFee()` to
display the total late fee. Implement a derived class `Book` where it will implement the abstract method
`calculateLateFee()` in this derived class by passing `daysLate` and `dailyFee` as parameters. Take user input
(`daysLate` and `dailyFee`) to calculate the late fee. Write the Java interface and class to implement this
system. Include a main method to demonstrate the functionality by taking user inputs and displaying the
calculated late fee.
3. Create a package named “company_package” and create 2 classes named “Employee_Info” and
“Department_Info” inside the company_package. The “Employee_Info” class should have variables like
emp_name, emp_id, age, and address. The “Department_Info” class should have variables like dept_name,
dept_id, and num_employees. Create another package named “manager_package” and create a class named
“Manager_Info” inside it. The “Manager_Info” class should have variables like manager_name, manager_id,
and department. Use parameterized constructors for all three classes to initialize the values of the variables.
Use a method “displayInfo()” to display the details in the respective classes. Create an object in the main
class to call the methods in both packages and initialize the values through the constructors.
4. Write a program in Java to display the name, employee ID, salary, department, and performance rating of
employees. Calculate the annual bonus based on the performance rating. Initialize respective array variables
for 15 employees. Handle ArrayIndexOutOfBoundsException, so that any such problem doesn’t cause illegal
termination of the program. Include exception handling to manage any other possible runtime exceptions,
ensuring the program runs smoothly.
5. Write a program in Java to display the name, student ID, age, course, and GPA of students. Calculate the
eligibility for a scholarship based on the GPA. Initialize respective array variables for 20 students. Handle
ArrayIndexOutOfBoundsException to prevent illegal termination of the program. Additionally, implement
exception handling to manage possible runtime exceptions such as NullPointerException and
InputMismatchException, ensuring the program continues to run smoothly.
6. Write a Java program to create an ArrayList named "Product" inside a "Store" class where the main method
is present. Add the name, price, and category of ten products to the ArrayList. Create another class named
"ProductComparator" that implements Comparator to sort all products according to price in ascending order
and display the product list before and after sorting using Comparator. Define a method named
`sortProducts()` in the "Store" class to perform the sorting operation.
7. Write a java program to define a generic constructor of the "Employee" class. Create three objects of the
"Employee" class from the "Main" class (derived class) to send salary of three employees as a parameter. For
the first employee, the salary amount should be sent as an integer. For the second employee, the salary amount
should be sent as a float. Similarly, for the third employee the salary amount should be sent as a string.
Finally, call the display() method available in the "Employee" class to display salary of all the three
employees.
8. Consider the following elements stored in an array list, List={12,73,42,11,22,56,43}. Create a multithread
class to arrange the elements. Use ascending method to arrange the elements in ascending order and use
descending method to arrange the elements in descending order. Ensure concurrent modification exception
should not occur when two thread objects access the ascending and descending methods at the same time.
9. Develop a multi-threaded hostel room allotment system in Java. Multiple students can request rooms
simultaneously, and the system must ensure that no two students are allocated the same room. Additionally,
students can check the availability of rooms at any time. Explain how you would ensure that room allotment
is thread-safe and no two students can book the same room. Also, describe how you can allow students to
check room availability without blocking other operations. Use appropriate synchronization mechanisms to
handle the above scenarios.

You might also like