0% found this document useful (0 votes)
1 views2 pages

Java Lab Modifications With Answers

The document outlines possible modifications for five different programming tasks: Encapsulation, Array of Objects, String Operations, Employee Record System, and Shopping Cart System. Each program includes specific enhancements such as adding getters/setters, searching for students, validating email formats, appending data, and sorting products. The modifications aim to improve functionality, data management, and user experience across the programs.

Uploaded by

Bhoomika Kc
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)
1 views2 pages

Java Lab Modifications With Answers

The document outlines possible modifications for five different programming tasks: Encapsulation, Array of Objects, String Operations, Employee Record System, and Shopping Cart System. Each program includes specific enhancements such as adding getters/setters, searching for students, validating email formats, appending data, and sorting products. The modifications aim to improve functionality, data management, and user experience across the programs.

Uploaded by

Bhoomika Kc
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

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.

You might also like