// class Pass - passing the faculty requirements
import javax.swing.*;
public class Pass{
private int [][] grades = { { -100, 80, 60, 45, 84, 80},
{ 85, -100, 50, 95, 95, 73},
{ 67, 55, 93, 86, 56, 87},
{ 82, 56, 84, -100,100, 74},
{ 87, 76, 98 , 74, 55, 88},
{ 98, 95, 85, -100, 87, 90},
{ 60, -100, 49, 55, 85,78} };
private boolean [] required = {true, false, true, true, false, true };
//compute the number of students who passed the requirements
public int passed ()
{
int count_passed =0;
// go over all students
for ( int i=0; i< grades.length; i ++)
{
// count tne number of courses in which a student failed or did not take the exam
int count = 0;
for ( int j=0; j< grades[0].length; j++)
if ( grades[i][j] == - 100 || grades[i][j] < 55)
count++;
// compute the student average in required courses
int count1 =0, sum = 0;
for ( int j=0; j< grades[0].length; j++)
if ( required[j] &&grades[i][j] != - 100 )
{
sum = sum + grades[i][j];
count1++;
}
double average = (double) sum / count1;
// decide if student passed
if ( count <= 1 && average >= 60 )
count_passed++;
else if ( count == 2 && average > 70 )
count_passed++;
}
return count_passed;
}
// copmute the number of students who failed the requirements
public int failed ()
{
int count_failed =0;
// go over all students
for ( int i=0; i< grades.length; i ++)
{
// count tne number of courses in which a student failed or did not take the exam
int count = 0;
for ( int j=0; j< grades[0].length; j++)
if ( grades[i][j] == - 100 || grades[i][j] < 55)
count++;
// compute the student average in required courses
int count1 =0, sum = 0;
for ( int j=0; j< grades[0].length; j++)
if ( required[j] &&grades[i][j] != - 100 )
{
sum = sum + grades[i][j];
count1++;
}
double average = (double) sum / count1;
// decide if student failed
if ( count <= 1 && average < 60 )
count_failed++;
else if ( count == 2 && average <= 70 )
count_failed++;
else if (count >=3)
count_failed++;
}
return count_failed;
}
// compute the percent of students who passed the requirements
public double percent ()
{
int count_passed =0;
// go over all students
for ( int i=0; i< grades.length; i ++)
{
// count tne number of courses in which a student failed or did not take the exam
int count = 0;
for ( int j=0; j< grades[0].length; j++)
if ( grades[i][j] == - 100 || grades[i][j] < 55)
count++;
// compute the student average in required courses
int count1 =0, sum = 0;
for ( int j=0; j< grades[0].length; j++)
if ( required[j] &&grades[i][j] != - 100 )
{
sum = sum + grades[i][j];
count1++;
}
double average = (double) sum / count1;
// decide if student passed
if ( count <= 1 && average >= 60 )
count_passed++;
else if ( count == 2 && average > 70 )
count_passed++;
}
return 100.0/grades.length*count_passed;
}
// return the maximal grade of a student in elective courses
public int max_elective ( int student)
{
int max = 0;
for ( int i=0; i< grades[0].length; i++)
if ( ! required[i] && grades[student][i] != - 100 &&grades[student][i] > max)
max = grades[student] [i] ;
return max;
}
// return the minimal grade of a student in elective courses
public int min_elective ( int student)
{
int min = 100;
for ( int i=0; i< grades[0].length; i++)
if ( ! required[i] && grades[student][i] != - 100 &&grades[student][i] < min)
min = grades[student] [i] ;
return min;
}
// return the minimal grade of a student in required courses
public int min_required ( int student)
{
int min = 100;
for ( int i=0; i< grades[0].length; i++)
if (required[i] && grades[student][i] != - 100 &&grades[student][i] < min)
min = grades[student] [i] ;
return min;
}
}
// Test class Pass
import javax.swing.*;
public class TestPass{
public static void main( String args[ ] )
{
// create the object
Pass p= new Pass ();
//compute the number of students who passed the requirements
int number = p.passed();
System.out.println ("the number of students who passed the requirements is " + number);
// copmute the number of students who failed the requirements
number = p.failed();
System.out.println ("the number of students who failed the requirements is " + number);
// compute the percent of students who passed the requirements
double per = p.percent();
System.out.println ("the percent of students who passed the requirements is " + per);
// compute the maximal grade of a student in elective courses
int student = 2;
int max = p.max_elective ( student);
System.out.println ( "the maximal grade of the student in elective courses is " + max);
// compute the minimal grade of a student in elective courses
int min = p.min_elective ( student);
System.out.println ( "the minimal grade of the student in elective courses is " + min);
// compute the minimal grade of a student in required courses
min = p.min_required ( student);
System.out.println ( "the minimal grade of the student in required courses is " + min);
}
}