-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentMenu.java
114 lines (97 loc) · 2.98 KB
/
StudentMenu.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import java.util.*;
public class StudentMenu {
public static void main(String []args){
Scanner sc=new Scanner(System.in);
studentop op=new studentop();
int p;
System.out.println("------------------------------------");
System.out.println("1.add the student\n2.display all the student\n3.specific student\n4.Exit..");
System.out.println("------------------------------------");
do{
System.out.println("Enter the operation:");
p=sc.nextInt();
switch(p){
case 1:
op.addStudent();
break;
case 2:
op.display();
break;
case 3:
op.specific();
break;
case 4:
System.out.println("Exiting...");
break;
}
}while(p!=4);
sc.close();
}
}
class studentop{
student data[]=new student[10];
Scanner sc=new Scanner(System.in);
int Rollno=0;
public void addStudent(){
System.out.println("Enter Number of student to add:");
int t=sc.nextInt();
for(int i=0;i<t;i++){
System.out.println("Name :");
String n=sc.next();
System.out.println("Dept:");
String d=sc.next();
System.out.println("Marks:");
int m[]=new int[5];
for(int j=0;j<5;j++){
m[i]=sc.nextInt();
}
student obj=new student(n,d,m);
data[Rollno]=obj;
Rollno++;
}
}
public void display(){
for(int i=0;i<Rollno;i++){
System.out.println("----------------------------------");
System.out.println("Rollno:"+(i+1));
System.out.println("Name :"+data[i].getName());
System.out.println("Dept :"+data[i].getdept());
System.out.println("-----------------------------------");
}
}
public void specific(){
System.out.println("Enter the student rollno:");
int x=sc.nextInt();
System.out.println("Rollno:"+(x));
System.out.println("Name :"+data[x-1].getName());
System.out.println("Dept :"+data[x-1].getdept());
System.out.println("Avg :"+avg(data[x-1].getmark()));
}
public static int avg(int m[]){
int sum=0;
for(int j=0;j<m.length;j++){
sum+=m[j];
}
System.out.println("Total :"+sum);
return sum/5;
}
}
class student{
private String name="";
private String dept="";
private int mark[]=new int[5];
student(String a,String b,int c[]){
this.name=a;
this.dept=b;
this.mark=c;
}
public String getName(){
return name;
}
public String getdept(){
return dept;
}
public int[] getmark(){
return mark;
}
}