Program 1: Encapsulation - Possible Modifications With Answers
• Add getter and setter for private variable: Getter method returns the private value, setter updates
it.
• Access protected variable through inheritance: Create a subclass and call protected members.
• Make default variable public to allow access outside the package.
• Demonstrate encapsulation by restricting direct access and using methods for data control.
Program 2: Array of Objects - Possible Modifications With
Answers
• Search a student by name: Loop through array and compare names.
• Find oldest and youngest student: Track max and min age values.
• Replace array with ArrayList to allow dynamic resizing.
• Add validation to avoid negative age input using conditional checks.
Program 3: String Operations - Possible Modifications With
Answers
• Use regex to validate email: Pattern class checks if email matches standard format.
• Count consonants as well by checking non-vowel letters.
• Reverse the string using StringBuilder reverse().
• Find length of each word using split() and length property.
Program 4: Employee Record System - Possible Modifications
With Answers
• Append data instead of overwriting: Use FileWriter(filename, true).
• Display data in table format by printing columns aligned.
• Delete record by ID: Read file into list, remove matching entry, rewrite file.
• Handle FileNotFoundException using try-catch for safe program execution.
Program 5: Shopping Cart System - Possible Modifications With
Answers
• Sort products in descending order using Comparator with reversed().
• Prevent duplicate product ID by checking if ID already exists before adding.
• Use HashMap for faster search and removal.
• Add total cart value calculation by summing item prices.