Practical 3 Oops
Practical 3 Oops
Roll no – 16
Code:
Main class
package Practical3;
import java.util.Scanner;
switch (choice) {
case 1:
{
int[] marks=new int[3];
sc.nextLine();
System.out.println("Enter name:");
String name = sc.nextLine();
System.out.println("Enter marks of 3
subjects");
for(int i=0;i<marks.length;i++) {
marks[i] = sc.nextInt();
}
String rollnumber =
studentmgt.generateroll();
student ns=new
student(name,rollnumber,marks);
studentmgt.addstudent(s,ns);
break;
}
case 2:{
studentmgt.displayall(s);
break;
}
case 3: {
System.out.println("Enter the
student's roll you want to search");
System.out.println(stud.roll);
for(int i=0;i<stud.marks.length;i++)
{
System.out.println(stud.marks[i]);
}
}
break;
}
case 4: {
studentmgt.averageCal(ss);
break;
}
case 5:
{
System.out.println("Enter the roll
number of student");
String rollnumber = sc.nextLine();
System.out.println("Enter the New
Name");
}
default :
{
System.out.println("Enter correct
choice");
}
}
}
Class Student :
package Practical3;
import java.util.Scanner;
switch (choice) {
case 1:
{
int[] marks=new int[3];
sc.nextLine();
System.out.println("Enter name:");
String name = sc.nextLine();
System.out.println("Enter marks of 3
subjects");
for(int i=0;i<marks.length;i++) {
marks[i] = sc.nextInt();
}
String rollnumber =
studentmgt.generateroll();
student ns=new
student(name,rollnumber,marks);
studentmgt.addstudent(s,ns);
break;
}
case 2:{
studentmgt.displayall(s);
break;
}
case 3: {
System.out.println("Enter the
student's roll you want to search");
System.out.println(stud.roll);
for(int i=0;i<stud.marks.length;i++)
{
System.out.println(stud.marks[i]);
}
}
break;
}
case 4: {
studentmgt.averageCal(ss);
break;
}
case 5:
{
System.out.println("Enter the roll
number of student");
String rollnumber = sc.nextLine();
System.out.println("Enter the New
Name");
}
default :
{
System.out.println("Enter correct
choice");
}
}
}
Class Student Management:
package Practical3;
}
static student search(student[] s1,String rollno) {
for(int i=0;i<=count-1;i++) {
if((s1[i].roll).equals(rollno)) {
return s1[i];
}
}
System.out.println("student not found !!!");
return null;
}
static void averageCal(student[] ss) {
double thindi = 0;
double tmaths =0;
double tphy =0;
if(ss != null) {
for (int i = 0; i < counterroll-1; i++) {
thindi += ss[i].marks[0];
tmaths += ss[i].marks[1];
tphy += ss[i].marks[2];
}
double a1 = thindi / markslimit;
double a2 = tmaths / markslimit;
double a3 = tphy /markslimit ;
System.out.println("Hindi average" + a1);
System.out.println("Maths average" + a2);
System.out.println("Physics average" + a3);
}
}
}
}