0% found this document useful (0 votes)
27 views7 pages

Practical 3 Oops

fefewewgwegevwvewbw

Uploaded by

hassanmansuri570
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views7 pages

Practical 3 Oops

fefewewgwegevwvewbw

Uploaded by

hassanmansuri570
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Practical 3

Name – Hassan Mansuri

Roll no – 16

Code:

Main class

package Practical3;

import java.util.Scanner;

public class main {


public static void main(String[] args) {
studentmgt m = new studentmgt();

Scanner sc = new Scanner(System.in);

student[] s = new student[100];


student []ss = s;
int choice;
while(true) {
System.out.println("Enter 1 for Add
student");
System.out.println("Enter 2 for Display all
students");
System.out.println("Enter 3 for Search for a
Student");
System.out.println("Enter 4 for Displaying
Average marks in each subject");
System.out.println("Enter 5 for Updating
student information");

System.out.println("Enter your choice: ");


choice = sc.nextInt();

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");

String target = sc.next();


student stud =
studentmgt.search(s,target);
if(stud != null) {
System.out.println(stud.name);

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;

public class main {


public static void main(String[] args) {
studentmgt m = new studentmgt();

Scanner sc = new Scanner(System.in);

student[] s = new student[100];


student []ss = s;
int choice;
while(true) {
System.out.println("Enter 1 for Add
student");
System.out.println("Enter 2 for Display all
students");
System.out.println("Enter 3 for Search for a
Student");
System.out.println("Enter 4 for Displaying
Average marks in each subject");
System.out.println("Enter 5 for Updating
student information");

System.out.println("Enter your choice: ");


choice = sc.nextInt();

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");

String target = sc.next();


student stud =
studentmgt.search(s,target);
if(stud != null) {
System.out.println(stud.name);

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;

public class studentmgt {


static int markslimit=0;
static int count = 0;
static int counterroll=0;

static String generateroll() {


String prefix = "CSE23RW";
String rollno = prefix + String.format("%04d",
counterroll + 1);
counterroll = counterroll+1;
return rollno;

static void addstudent(student[] s, student ns) {


if(count > 99) {
System.out.println("Error Adding student ,,
Limit Exceeded");
}
s[count] = ns;
count = count + 1;
markslimit++;
}

static void displayall(student[] s) {


String roll = generateroll();
for (int i = 0; i < count; i++) {
System.out.println(s[i].name + " " +
s[i].roll + " ");
for (int j = 0; j < s[i].marks.length; j++) {
System.out.println(s[i].marks[j]);
}
}

}
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);
}
}

static void updater(student []sp , String roll) {


student chn = search(sp , roll);
System.out.println("Enter the new Name");

}
}

You might also like