1A- Code a multi-threaded Java application that displays a student who has the highest GPA in a class. You must code two classes, namely HighestGPA and Worker. For the HighestGPA class, you only need to code the main method. The main method will do the following tasks:
It invokes a static method to have an ArrayList of student objects. The static method is declared in the HighestGPA class as follows:
public static ArrayListgetStudents( );
It creates 3 threads to search three separate arrays of students and find out three students with the highest GPAs among their own peers. (Note: You must use the ArrayList to create three arrays of students. You can assume that the total number of students stored in the ArrayList is divided evenly by 3. In other words, each thread has the same number of students as its workload. )
It displays the student with the highest GPA. (Note: If two or more students have the same highest GPA, the main method will select the youngest student. This rule of selecting the youngest student also applies to the threads. We assume that all students have different ages.)
The Worker class is used to create threads as Java objects. It has a constructor that takes an array of student objects. A Worker thread will find the student with the highest GPA. You must code this class completely. You may use the Student class in your coding.
You are not required to code the Student class. It has the following API:
public Student( );
public Student( String name, double gpa, int age );
public String getName();
public double getGPA();
public int getAge();
public void setName( String name );
public void setGPA( double gpa );
public void setAge( int age );
Here is a possible scenario.
There are 9 students in the ArrayList:
The first thread will search an array of the first three students. It will find “John Doe” to be the student with the highest GPA. The second thread will search an array of the next three students. It will find “May Sanders” to be the student with the highest GPA. The third thread will search an array of the last three students. It will find “Paul Newman” to be the student with the highest GPA. The main method will select “May Sanders” as the youngest student with the highest GPA.
1-B Code a multi-threaded Java application that displays a student who has the lowest GPA in a class. You must code two classes, namely LowestGPA and SearchThread. For the LowestGPA class, you only need to code the main method. The main method will do the following tasks:
It invokes a static method to have an ArrayList of student objects. The static method is declared in the LowestGPA class as follows:
public static ArrayListgetStudents( );
It creates 3 threads to search three separate arrays of students and find out three students with the lowest GPAs among their own peers. (Note: You must use the ArrayList to create three arrays of students. You can assume that the total number of students stored in the ArrayList is divided evenly by 3. In other words, each thread has the same number of students as its workload. )
It displays the student with the lowest GPA. (Note: If two or more students have the same lowest GPA, the main method will select the youngest student. This rule of selecting the youngest student also applies to the threads. We assume that all students have different ages.)
The SearchThread class is used to create threads as Java objects. It has a constructor that takes an array of student objects. A Worker thread will find the student with the highest GPA. You must code this class completely. You may use the Student class in your coding.
You are not required to code the Student class. It has the following API:
public Student( );
public Student( String name, double gpa, int age );
public String getName();
public double getGPA();
public int getAge();
public void setName( String name );
public void setGPA( double gpa );
public void setAge( int age );
Here is a possible scenario.
There are 9 students in the ArrayList:
The first thread will search an array of the first three students. It will find “John Doe” to be the student with the lowest GPA. The second thread will search an array of the next three students. It will find “May Sanders” to be the student with the lowest GPA. The third thread will search an array of the last three students. It will find “Paul Newman” to be the student with the lowest GPA. The main method will select “May Sanders” as the youngest student with the lowest GPA.