-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram17_StudentClass.java
More file actions
53 lines (46 loc) · 1.62 KB
/
Program17_StudentClass.java
File metadata and controls
53 lines (46 loc) · 1.62 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
/*Write a Java program to create class Student.
The class should have attributes student ID, student name, marks for 3 subjects and the member functions are setdata() and displaydata().
Calculate the average marks for student.*/
// Date : 03/01/2024, Author : Yash Wadhvani
import java.util.*;
public class Program17_StudentClass {
public static void main(String[] args) {
Student stu1 = new Student();
stu1.setData();
stu1.displayData();
}
}
class Student {
int ID;
String Name;
double[] marks = { 0, 0, 0 };
double a, b, c, avg;
Scanner sc = new Scanner(System.in);
public void setData() {
System.out.println("Enter Student ID :-");
ID = sc.nextInt();
System.out.println("Enter Student Name :-");
Name = sc.next();
System.out.println("Enter Marks of Subject 1:-");
a = sc.nextDouble();
System.out.println("Enter Marks of Subject 2:-");
b = sc.nextDouble();
System.out.println("Enter Marks of Subject 3:-");
c = sc.nextDouble();
marks[0] = a;
marks[1] = b;
marks[2] = c;
avg = (a + b + c) / 3;
}
public void displayData() {
System.out.println("Student ID = " + ID);
System.out.println("Student Name = " + Name);
System.out.println("Marks of Subject 1= " + a);
System.out.println("Marks of Subject 2= " + b);
System.out.println("Marks of Subject 3= " + c);
for (int i = 0; i < marks.length; i++) {
System.out.println(marks[i]);
}
System.out.println(String.format("Average Marks = %.2f", avg));
}
}