-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentDemo.java
More file actions
34 lines (34 loc) · 1.04 KB
/
StudentDemo.java
File metadata and controls
34 lines (34 loc) · 1.04 KB
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
class Student {
String name;
int rollNumber;
int maths;
int english;
int science;
float average;
Student(String name, int rollNumber, int maths, int english, int science){
this.name=name;
this.rollNumber=rollNumber;
this.maths=maths;
this.english=english;
this.science=science;
}
public void calculateAverage() {
average = (maths+english+science)/3;
}
public void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Roll Number: " + rollNumber);
System.out.println("Marks for Maths: " + maths+"\nMarks for English: " + english +"\nMarks for Science: " +science);
System.out.println("Average Marks: " + average);
}
}
public class StudentDemo {
public static void main(String[] args) {
Student s1= new Student("John",20,50,45,48);
s1.calculateAverage();
s1.displayDetails();
Student s2= new Student("Joshil",22,40,45,48);
s2.calculateAverage();
s2.displayDetails();
}
}