-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentMarks.java
More file actions
63 lines (51 loc) · 1.56 KB
/
Copy pathStudentMarks.java
File metadata and controls
63 lines (51 loc) · 1.56 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.io.*;
import java.util.Scanner;
class Student{
public String name;
protected int mark1;
protected int mark2;
protected int mark3;
void total(){
System.out.println("Total mark : " + (mark1 + mark2 + mark3));
System.out.println("\n");
}
private void average(){
double avg = (mark1 + mark2 + mark3) / 3;
System.out.println("Average : " + avg);
}
void display(){
System.out.println("Name of the student : " + name);
System.out.println("Mark in 1st subject : " + mark1);
System.out.println("Mark in 2nd subject : " + mark2);
System.out.println("Mark in 3rd subject : " + mark3);
}
}
public class StudentMarks {
public static void main(String[] args){
System.out.println("Student marks and average of 3 subjects:\n");
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
s1.name="Deepthi";
s1.mark1 = 98;
s1.mark2 = 97;
s1.mark3 = 99;
s2.name="Preethi";
s2.mark1 = 99;
s2.mark2 = 100;
s2.mark3 = 96;
s3.name="Shreya";
s3.mark1 = 75;
s3.mark2 = 80;
s3.mark3 = 90;
s1.display();
s1.total();
//s1.average(); shows error since sverage() is private
s2.display();
s2.total();
//s2.average(); shows error since sverage() is private
s3.display();
s3.total();
//s3.average(); shows error since sverage() is private
}
}