Question
Write a method that will return a list of students expected to graduate in a particular year. The user will be prompted for and enter
Write a method that will return a list of students expected to graduate in a particular year.
The user will be prompted for and enter a number of students in the school. The program should then prompt for and read names and graduation years of each student. These will be stored into two separate arrays.s The array names will hold the full name of each student. The array gradYear will hold the corresponding graduation year for the student in the same element of the names array.
Important: You can assume there will never be more than 100 students so both arrays can be declared to hold 100 elements of the type (String or int).
Implement a method called listGraduates whose prototype should be:
public static String[] listGraduates(String[] names, int[] gradYears, int yearOfGrad, int elementCount)
The two arrays hold the data collected about each student. The third argument is the graduation year to search for, and the final argument is the count of valid elements in the names and gradYears arrays. The method should only process that many elements of each array.
It will build and return a list of names in a string array. The string array will have 1 element for each student. At the end of the array, there should be a sentinel value (this is a value that is not valid for the data expected). As a sentinel, use the string 0.
The main procedure should use the console to prompt the user and read the names of each student and their graduating year. It will build the two arrays described above and then call listGraduates. When listGraduates returns a String array with the graduating students, then main should print the names, one per line. The main will know the end of valid data when it reaches a name that is 0.
Example run:
Enter number of students: 8
Student name: Joseph Cool
Graduating year: 2019
Student name: Jane Doe
Graduating year: 2020
Student name: Beth Good
Graduating year: 2019
Student name: Tanner McPherson
Graduating year: 2018
Student name: Terry Able
Graduating year: 2019
Student name: Susan Anspach
Graduating year: 2018
Student name: Trent Kearny
Graduating year: 2020
Student name: Nancy Galt
Graduating year: 2018
List for which year? 2019
Graduating Students:
Joseph Cool
Beth Good
Terry Able
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started