-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student.java
50 lines (37 loc) · 991 Bytes
/
Student.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.array;
import java.util.Arrays;
public class Student {
String name;
int[] listOfMarks;
Student(String name, int listOfMarks[]) {
this.name = name;
this.listOfMarks = listOfMarks;
}
public int getTotalSumMarks() {
int sum = 0;
for (int mark : listOfMarks) {//enhaced for loop provided in java 5 for creating loop around array listOfMarks
sum = sum + mark;
}
return sum;
}
public int getNumberOfMarks() {
int number;
number = listOfMarks.length;//array property og getting length of array
return number;
}
public int getMaxMarks() {
Arrays.sort(listOfMarks);//array static method to sort an array
int number;
number = listOfMarks.length;
return listOfMarks[number - 1];
}
public int getMinMark() {
return listOfMarks[0];
}
public int getAverageMarks() {
int sum = getTotalSumMarks();
int number = getNumberOfMarks();
int average = sum / number;
return average;
}
}