OOP Exercises for Java Applications
OOP Exercises for Java Applications
Method overloading is used in the 'identifyMarks' method to determine a student's marks based on whether they passed on their first or second attempt. If the 'secondChance' is false, a single float argument method sets the marks. If 'secondChance' is true, a two-float arguments method computes the maximum of first and second chances' marks to set the final score .
The program should handle setting the 'empDesig' attribute by checking if the given designation matches one of the predefined values: developer, tester, Lead, or manager. If the designation does not match any of these values, the setter method should display an 'Invalid designation' error message .
A method should iterate through an array of Student objects, comparing their scores using a loop or sorting technique. The student with the highest score should be returned by the method, ensuring efficient data processing within the program .
The Java program should check the 'secondChance' boolean variable. If it is false, the program should invoke the 'identifyMarks(float)' method. If true, it should invoke 'identifyMarks(float, float)' method to process and set the marks based on both attempts .
The 'empDept' setter should verify if the input matches allowed department values: TTH, RCM, Digital, or DevOps. If none of these values are matched, the setter should display an 'Invalid Dept' error message, ensuring that only valid department codes are accepted .
An admin can register a customer by filling either: only ID, name, and address; only ID and name; or all details. When not all data members are initialized through constructors, appropriate default values should be set for these uninitialized fields to maintain data integrity .
Handling null pointers is crucial to prevent runtime exceptions and ensure program stability. For 'empName', the 'setEmpName()' method should include a null check, and if null is encountered, an appropriate error message should be displayed to notify about the issue .
Constructor overloading allows for different initialization paths when registering customers. By providing multiple constructors with varying parameters, the system can accommodate different amounts of customer information, such as ID only, ID and name, or ID, name, and address, enhancing flexibility in customer data handling .
The program should consider tracking each book's title, price, year of publication, and author's name. Instances should be created for specific books like 'Robinson Crusoe' by Daniel Defoe, 'Heart of Darkness' by Joseph Conrad, and 'Beach Music' by Pat Conroy, with their respective details . The program should also ensure accurate data representation and retrieval functionalities for the bookstore's inventory management.
The menu-driven program should include functionalities to create student records, display student names sorted alphabetically by branch, and display student IDs in ascending order. These functionalities ensure efficient organization and retrieval of student data .