-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentAverage.java
More file actions
37 lines (33 loc) · 996 Bytes
/
StudentAverage.java
File metadata and controls
37 lines (33 loc) · 996 Bytes
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
// Create a student class
// -create 5 student objects and store it in
// a proper datastructure
// - find the average marks of the students
class Student {
String name;
int marks;
// Constructor
public Student(String name, int marks) {
this.name = name;
this.marks = marks;
}
}
public class StudentAverage {
public static void main(String[] args) {
// Creating an array to store Student objects
Student[] students = {
new Student("Alice", 85),
new Student("Bob", 78),
new Student("Charlie", 92),
new Student("David", 74),
new Student("Emma", 88)
};
// Calculate average marks
int totalMarks = 0;
for (Student student : students) {
totalMarks += student.marks;
}
double average = (double) totalMarks / students.length;
// Print the average
System.out.println("Average Marks: " + average);
}
}