Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Classroom {
- public Student[] students;
- public String className;
- public Classroom(String className, int numStudents){
- this.className = className;
- this.students = new Student[numStudents];
- }
- public void addStudent(){
- Scanner sc = new Scanner(System.in);
- for (int i = 0; i < students.length; i++) {
- System.out.println("Enter a student name: " + (i + 1) + ": ");
- String name = sc.nextLine();
- System.out.println("Enter the number of grades: ");
- int numGrades = sc.nextInt();
- int[] grades = new int[numGrades];
- for (int j = 0; j < numGrades; j++) {
- System.out.println("Enter grade: " + (j + 1) + ": ");
- grades[j] = sc.nextInt();
- }
- sc.nextLine();
- students[i] = new Student(name, grades);
- }
- }
- public void displayStudents() {
- System.out.println("Class: " + className);
- for (Student student : students) {
- student.displayInfo();
- System.out.println("Average grade: " + student.calcAverage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement