Sunday 11 June 2017

Java Code to find out Student Pass Count

Problem:

Given a set of n students examination marks (in the range 0 to 100) make a count of the number of students that passed the examination. A pass is awarded for all marks of 50 and above.

Algorithm:

1. Prompt then read the number of marks to be processed.
2. Initialize count to zero.
3. While there are still marks to be processed repeatedly do
     a. read next mark
     b. if it is a pass (i.e >=50) then add one to count.
4. Write out total number of passes


Solution:

package com.myprograms;
//Algorithm 2.2
import java.util.Scanner;

public class StudentPassCount {
int a[];
static Scanner s = null;
static int counter = 0;

public StudentPassCount(int n){
a = new int[n];
}

private void initializeMarks(){
for(int i = 0; i< a.length; i++){
System.out.println("enter the marks");
a[i] = s.nextInt();
}
}

private void findPassedStudents(){
for(int i = 0; i< a.length; i++){
if(a[i] >= 50){
counter = counter + 1;
}
}
}


public static void main(String[] args) {
s = new Scanner(System.in);
System.out.println("How many students marks you want to verify??");
StudentPassCount sp = new StudentPassCount(s.nextInt());
sp.initializeMarks();
sp.findPassedStudents();
System.out.println("the count of passed students is: "+counter);
}
}


Output:
How many students marks you want to verify??
3
enter the marks
56
enter the marks
78
enter the marks
35
the count of passed students is: 2


No comments:

Post a Comment

Program for primality test in JAVA

Problem: ============= Program for primality test in JAVA What is primality test? A primality test is an algorithm for determining wh...