- Create a class called
Studentwith the following:- Private fields:
String nameint iddouble[] grades(store 5 grades)
- A constructor to initialize all fields.
- Getter methods for
nameandid. - A method
calculateAverage()that returns the average of the grades. - A method
getHighestGrade()that returns the highest grade. - A method
hasPassed()that returnstrueif the average is 60 or higher.
- Private fields:
- In the
mainmethod:- Ask the user to enter:
- Student name
- Student ID
- 5 grades
- Create a
Studentobject. - Display:
- Student name and ID
- Average grade
- Highest grade
- Whether the student passed or failed
- Ask the user to enter:
Example Question Format (Specific Detail)
How do you properly encapsulate the
gradesarray in theStudentclass to prevent external modification, while still allowing calculation of the average and highest grade?
This question focuses on:
- Encapsulation
- Arrays in objects
- Access modifiers
- Object-oriented design principles
If you’d like, I can also give you:
- A debugging-type Java problem
- An object-oriented design problem
- A data structures problem in Java
- A beginner-level Java problem
- An advanced interview-style Java problem
Requirements:

Leave a Reply
You must be logged in to post a comment.