THINK FIRST·CODE LATER

← All labs

ArrayList of students

Problem

Write a class Student with private fields name and grade (int), a constructor, getName(), getGrade() and toString() returning name (grade).

StudentList reads a count n, then n pairs name grade (the name is one word), stores the students in an ArrayList<Student>, and prints:

Students: 3
Best: Amina (91)
Above average: 1

(With 91, 78 and 84 the average is 84.33, so only one student is strictly above it.)

Best is the student with the highest grade, Above average counts the students whose grade is strictly greater than the average.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l13-1-data-1.txt

3 Amina 91 LiWei 78 Ousmane 84
What your program must print for l13-1-data-1.txt
Students: 3

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l13-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content l13-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.