57.8k views
2 votes
Create a HighestGrade application that prompts the user for five grades between 0 and 100 points and stores the grades in an ArrayList. HighestGrade then traverses the grades to determine the highest grade and then displays the grade along with an appropriate message.

1 Answer

6 votes

Final answer:

To create the HighestGrade application, you need to prompt the user for five grades and store them in an ArrayList. Then, traverse the ArrayList to determine the highest grade and display it with a message.

Step-by-step explanation:

In order to create the HighestGrade application, you will need to follow these steps:

  1. Create an ArrayList variable to store the grades.
  2. Use a loop to prompt the user for five grades and add them to the ArrayList.
  3. Create a variable to track the highest grade and initialize it to the first grade in the ArrayList.
  4. Traverse the ArrayList and compare each grade to the highest grade variable. If a higher grade is found, update the highest grade variable.
  5. After traversing the ArrayList, display the highest grade along with an appropriate message.

Here's an example code snippet:

import java.util.ArrayList;
import java.util.Scanner;

public class HighestGrade {
public static void main(String[] args) {
ArrayList grades = new ArrayList();
Scanner scanner = new Scanner(System.in);

for (int i = 0; i < 5; i++) {
System.out.print("Enter grade " + (i + 1) + ": ");
int grade = scanner.nextInt();
grades.add(grade);
}

int highestGrade = grades.get(0);
for (int i = 1; i < grades.size(); i++) {
int grade = grades.get(i);
if (grade > highestGrade) {
highestGrade = grade;
}
}

System.out.println("The highest grade is " + highestGrade);
}
}

User Herrlock
by
7.8k points