Write a method that meets the requirements of the following comment header block
ID: 3771871 • Letter: W
Question
Write a method that meets the requirements of the following comment header block. findMaxGPA the purpose of this method is to find the index of the maximum grade point average within the array. If two students have the same gpa, then choose the highest index value to break that tied value. Input Argument: values array of grade point averages Return Value: maxlndex the index of the maximum grade point average Write a method that meets the requirements of the following comment header block. This method should use the method created in the previous problem. You may use either console PrintHighestGPA The purpose of this method is to print the name and grade point average for the student who has the highest gpa. The method will receive parallel arrays for input. Input Arguments: names the names of all students gpa Values the gpa value of all student Return Value: noneExplanation / Answer
/**
* @author Srinivas Palli
*
*/
Problem6.java
public class Problem6 {
/**
* method to get the index of the max grade
*
* @param inputGradePoints
* @return
*/
public static int findMaxGPA(int[] inputGradePoints) {
int maxIndex = 0;
int maxGrade = inputGradePoints[0];
for (int i = 1; i < inputGradePoints.length; i++) {
if (maxGrade <= inputGradePoints[i]) {
maxGrade = inputGradePoints[i];
maxIndex = i;
}
}
return maxIndex;
}
public static void main(String[] args) {
int[] inputGradePoints = { 70, 50, 80, 95, 94, 90 };
int maxGradeIndex = findMaxGPA(inputGradePoints);
System.out.println("Maximum Grade Index=" + maxGradeIndex);
}
}
Problem7.java
public class Problem7 {
/**
* method to print name and grade of maximum grade obtained
*
* @param inputGradePoints
* @param names
*/
public static void printHighestGPA(int[] inputGradePoints, String names[]) {
int maxGrade = inputGradePoints[0];
String maxGradeName = names[0];
for (int i = 1; i < inputGradePoints.length; i++) {
if (maxGrade <= inputGradePoints[i]) {
maxGrade = inputGradePoints[i];
maxGradeName = names[i];
}
}
System.out.println("Maximum Grade Details:");
System.out.println("Name :" + maxGradeName);
System.out.println("Grade:" + maxGrade);
}
public static void main(String[] args) {
int[] inputGradePoints = { 70, 50, 80, 95, 94, 90 };
String names[] = { "Srinivas", "Rajesh", "Pavan", "Chandu", "Kiran",
"Ravi" };
printHighestGPA(inputGradePoints, names);
}
}
OUTPUT:
Problem6:
Maximum Grade Index=3
Problem7:
Maximum Grade Details:
Name :Chandu
Grade:95
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.