Java Tutorial
Java Project: Student Manager
Store students in an ArrayList of objects, print the roster, and find the top score.
What you will build
A roster of students with name and score. Print everyone, then the highest score.
A Student class
Group name and score. Keep an ArrayList of Student objects.
Example
class Student {
String name;
int score;
Student(String name, int score) { this.name = name; this.score = score; }
}
public class Main {
public static void main(String[] args) {
java.util.List roster = java.util.List.of(
new Student("Rin", 88),
new Student("Kai", 91),
new Student("Ada", 95)
);
Student top = roster.get(0);
for (Student s : roster) {
System.out.println(s.name + " " + s.score);
if (s.score > top.score) top = s;
}
System.out.println("top: " + top.name);
}
} Practice
- Compile the complete program at
/java/try. - Change one input value and compile again.
- Replace a hardcoded number with
Scannerwhen you want typed input.