009-001-011
Private Modifier: Setter with Validation
Medium
Problem Description
Private Modifier: Setter with Validation
In this problem, you will create a program that implements range validation (0-100) in a Score class setter, tests both valid and invalid values, and displays the result to standard output.
Learning Objective: Understand how to perform validation in setters
Overview
Create a class with a setter that rejects invalid values.
Specifications
- Create a
Scoreclass - Private int field
value(range 0-100) setValue(int v)checks range (reset to 0 if out of range)getValue()retrieves value- Test with valid and invalid values in Main
Output Format
Valid score: 85
Invalid score reset to: 0
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up