GETRESULT :- Fully menu driven program for student result Just
Just put student marks and get which student get maximum and minimum, also get student result in Ascending order and delete student data if not necessary
//Student class
package array;
import java.util.Scanner;
/**
*
* @author india
*/
public class students
{
Scanner x=new Scanner(System.in);
private String student_name;
private String contact_no;
private long student_rollno;
private int subjects_marks[];
private double percentage;
int sum;
//parameterized constractor
students(){
sum=0;
subjects_marks=new int[3];
}
//for add details of student
public void add_details()
{
boolean a;
String subjects[]={"MATHS","CHEMISTRY","PHYSICS"};
System.out.print("\n\n\nENTER STUDENT'S NAME :- ");
student_name=x.next();
System.out.print("ENTER CONTACT NUMBER :- ");
contact_no=x.next();
System.out.print("ENTER STUDENT ROLL NO :- ");
student_rollno=x.nextInt();
int i;
for(i=0;i<3;i++)
{
int j=i;j++;
do{
System.out.print("ENTER MARKS OF "+subjects[i]+" :- ");
subjects_marks[i]=x.nextInt();
if(subjects_marks[i]>100)
{
System.out.printf("\nYour entered marks should be under 100 marks..........\n");
a=true;
}
else
{
a=false;
}
}while(a);
sum=sum+subjects_marks[i];
}
System.out.println("TOTAL MARKS :- "+sum+"\n");
percentage=sum/3;
System.out.println("STUDENT GOT "+percentage+"% percentage.\n\n\n");
}
//for getting percentage of student
public void get_percentage()
{
System.out.println(student_name+"\t\t"+student_rollno+"\t\t"+subjects_marks[0]+"\t\t"+subjects_marks[1]+"\t\t"+subjects_marks[2]+"\t\t"+sum+"\t\t"+percentage);
}
//for finding student who get maximum and minimum percentage
public void maxi_mini_per(students p[],int x)
{
int i;
int j=0,k=0;
double maxi;
double mini;
maxi=percentage;
mini=percentage;
for(i=1;i<x;i++)
{
if(p[i].percentage>maxi)
{
maxi=p[i].percentage;
j=i;
}
if(p[i].percentage<mini)
{
mini=p[i].percentage;
k=i;
}
}
System.out.println(p[j].student_name+" MAXIMUM "+maxi+"% AMONG ALL.");
System.out.println(p[k].student_name+" MINIMUM "+mini+"% AMONG ALL.\n\n");
}
//for getting list in descending order
public void discending(students p[],int x)
{
Scanner y=new Scanner(System.in);
int i,j,choice1,ans;
boolean b;
double temp1,temp2,temp3,temp4,temp5;
for(i=0;i<x-1;i++)
{
for(j=0;j<x-1-i;j++)
{
if(p[j].percentage>p[j+1].percentage)
{
temp1=p[j].percentage;
p[j].percentage=p[j+1].percentage;
p[j+1].percentage=temp1;
temp2=p[j].percentage;
p[j].percentage=p[j+1].percentage;
p[j+1].percentage=temp2;
temp3=p[j].percentage;
p[j].percentage=p[j+1].percentage;
p[j+1].percentage=temp3;
temp4=p[j].percentage;
p[j].percentage=p[j+1].percentage;
p[j+1].percentage=temp4;
temp5=p[j].percentage;
p[j].percentage=p[j+1].percentage;
p[j+1].percentage=temp5;
String strcopy=new String(p[j].student_name);
p[j].student_name=new String(p[j+1].student_name);
p[j+1].student_name=new String(strcopy);
}
}
}
do{
System.out.print(" 1 :- PERCENTAGE LIST :- \n");
System.out.print(" 2 :- TOTAL LIST.\n");
System.out.print(" 3 :- LIST OF MATHS MARKS.\n");
System.out.print(" 4 :- LIST OF CHEMISTRY MARKS.\n");
System.out.print(" 5 :- LIST OF PHYSICS MARKS.\n ");
System.out.print("choice :- ");
choice1=y.nextInt();
switch(choice1)
{
case 1:
System.out.print("NAME\tPERCENTAGE\n");
for(i=x-1;i>=0;i--)
{
System.out.println(p[i].student_name+"\t"+p[i].percentage);
}
break;
case 2:
System.out.print("NAME\tSUM\n");
for(i=x-1;i>=0;i--)
{
System.out.println(p[i].student_name+"\t"+p[i].sum);
}
break;
case 3:
System.out.print("NAME\tMATHS MARKS\n");
for(i=x-1;i>=0;i--)
{
System.out.println(p[i].student_name+"\t"+p[i].subjects_marks[0]);
}
break;
case 4:
System.out.print("NAME\tCHEMISTRY MARKS\n");
for(i=x-1;i>=0;i--)
{
System.out.println(p[i].student_name+"\t"+p[i].subjects_marks[1]);
}
break;
case 5:
System.out.print("NAME\tPHYSICS MARKS\n");
for(i=x-1;i>=0;i--)
{
System.out.println(p[i].student_name+"\t"+p[i].subjects_marks[2]);
}
break;
default:
System.out.print("\nPLEASE.....CHOICE RIGHT OPTION..\n\n");
}
System.out.println("YOU WANT TO GO IN MAIN MENU AGAIN :- ");
System.out.println("1 :- YES");
System.out.println("2 :- NO");
System.out.println("choice :- ");
ans=y.nextInt();
if(ans==1)
{
b=true;
}
else
{
b=false;
}
}while(b);
}
//student who pass or fail
public void pass_fail_list(students p[],int x)
{
int i;
System.out.print("NAME\t\tPERCENTAGE\tPASS/FAIL/CLASS\n");
for(i=0;i<x;i++)
{
if(p[i].percentage>80)
{
System.out.print(p[i].student_name+"\t"+p[i].percentage+"\tFIRSTCLASS\n");
}
else if(p[i].percentage<=80 && p[i].percentage>60)
{
System.out.print(p[i].student_name+"\t"+p[i].percentage+"\tSECONDCLASS\n");
}
else if(p[i].percentage<=60 && p[i].percentage>40)
{
System.out.print(p[i].student_name+"\t"+p[i].percentage+"\tTHIRDCLASS\n");
}
else
{
System.out.print(p[i].student_name+"\t"+p[i].percentage+"\tFAIL\n");
}
}
}
//top five student
public void top_five(students p[],int x)
{
int i,j;
double temp;
for(i=0;i<x-1;i++)
{
for(j=0;j<x-1-i;j++)
{
if(p[j].percentage>p[j+1].percentage)
{
temp=p[j].percentage;
p[j].percentage=p[j+1].percentage;
p[j+1].percentage=temp;
String strcopy=new String(p[j].student_name);
p[j].student_name=new String(p[j+1].student_name);
p[j+1].student_name=new String(strcopy);
}
}
}
System.out.print("NAME\tPERCENTAGE\n");
if(x>5)
{
for(i=x-1;i>x-6;i--)
{
System.out.println(p[i].student_name+"\t"+p[i].percentage+"\n");
}
}
else
{
for(i=x-1;i>=0;i--)
{
System.out.println(p[i].student_name+"\t"+p[i].percentage+"\n");
}
}
}
//for delete student details
public int delete_it(students p[],int x)
{
Scanner z=new Scanner(System.in);
int i,ans;
boolean b;
long which;
System.out.print("\n");
for(i=0;i<x;i++)
{
System.out.println(p[i].student_name+"'s roll number is "+p[i].percentage+"%");
}
System.out.print("\n\n");
do{
System.out.print("WHICH STUDENT'S DETAILS YOU WANT TO DELETE?? (ENTER ROLL NUMBER OF STUDENT):- ");
which=z.nextInt();
int j;
double temp5;
for(i=0;i<x;i++)
{
if(which==p[i].student_rollno)
{
if(i==(x-1))
{
x--;
}
else
{
for(j=i;j<x;j++)
{
temp5=p[j].percentage;
p[j].percentage=p[j+1].percentage;
p[j+1].percentage=temp5;
}
x--;
}
}
System.out.println("SELECTED STUDENT DETAILS ARE DELETED...");
System.out.println("YOU WANT TO DELETE ANOTHER STUDENT'S DETAILS AGAIN :- ");
System.out.println("1 :- YES");
System.out.println("2 :- NO");
System.out.println("choice :- ");
ans=z.nextInt();
if(ans==1)
{
b=true;
}
else
{
b=false;
}
}while(b);
return x;
}
}
/*
Main Class
*/
package array;
/**
*
* @author india
*/
import java.util.Scanner;
public class Array
{
private static students[] students;
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Scanner input=new Scanner(System.in);
students[] s;//this is array of reference variable not it is not still an object
int no_students,i,choice,ans,con;
boolean b;
System.out.print("-: SHREE SARASWATI VIDHYAMANDIR , UNJHA.................\n\n ");
System.out.print("-: STUDENTAPP :- \n\n ");
System.out.print("HOW MANY STUDENTS DATA YOU WAN TO ENTER :- ");
no_students=input.nextInt();
s=new students[no_students];//still this is array of reference variable
s[0]=new students();
s[0].add_details();
for(i=1;i<s.length;i++)
{
s[i]=new students();//now this is object of students class
s[i].add_details();
}
do
{
System.out.print("WHAT DO YOU WANT TO DO? :- \n");
System.out.print(" 1 :- SHOW LIST OF STUDENTS PERCENTAGE :- \n");
System.out.print(" 2 :- FIND WHICH STUDENT GOT MAXIMUM OR MINIMUM MARKS.\n");
System.out.print(" 3 :- STUDENT'S PERCENTAGE LIST IN ASCENDING ORDER.\n");
System.out.print(" 4 :- PASSING OR NOT.\n");
System.out.print(" 5 :- TOP FIVE STUDENTS.\n ");
System.out.print(" 6 :- DELETE DETAILS.\n");
System.out.print("ENTER YOUR CHOICE :- ");
choice=input.nextInt();
switch(choice)
{
case 1:
System.out.println("STUDENT NAME\t\tROLL NO\t\tMATHS\t\tCHEMISTRY\tPHYSICS\t\tTOTAL\t\tPERCENTAGE");
for(i=0;i<no_students;i++)
{
s[i].get_percentage();
}
break;
case 2:
System.out.print("\n\nSTUDENT WHO TOOK MAXIMUM OR MINIMUM PERCENTAGE ARE AS UNDER.\n\n");
s[0].maxi_mini_per(s,no_students);
break;
case 3:
System.out.print("\n\nSTUDENT PERCETAGE IN ASCENDING ORDER :- \n\n");
s[0].discending(s,no_students);
break;
case 4:
System.out.print("\n\nSTUDENT PASS OR FAILED LIST IS AS UNDER :- \n\n");
s[0].pass_fail_list(s,no_students);
break;
case 5:
System.out.print("\n\nTOP FIVE STUDENTS :- \n\n");
s[0].top_five(s,no_students);
break;
case 6:
System.out.print("DELETE STUDENT DETAILS THAT YOU WANT.....");
con=s[0].delete_it(s,no_students);
no_students=con;
default:
System.out.print("CHOICE IS NOT CORRECT...........\n");
}
System.out.println("YOU WANT TO GO IN MAIN MENU AGAIN :- ");
System.out.println("1 :- YES");
System.out.println("2 :- NO");
System.out.println("choice :- ");
ans=input.nextInt();
if(ans==1)
{
b=true;
}
else
{
b=false;
}
}while(b);
}
}
No comments:
Post a Comment