Advertisement
Vladkoheca

Student.java

Dec 13th, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | Source Code | 0 0
  1. public class Student {
  2.  
  3.     public String studentName;
  4.     public int[] grades;
  5.  
  6.     public Student(String studentName, int[] grades){
  7.         this.studentName = studentName;
  8.         this.grades = grades;
  9.     }
  10.  
  11.     public void displayInfo(){
  12.         System.out.println("Student: name: " + studentName + ", Grades:");
  13.         for (int grade : grades) {
  14.             System.out.println(grade + " ");
  15.         }
  16.         System.out.println();
  17.     }
  18.  
  19.     public int calcAverage() {
  20.         int total = 0;
  21.         for(int grade : grades) {
  22.             total += grade;
  23.         }
  24.         return (double) total / grades.length;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement