(i) A module is required to enable lecturers to easily identify the highest and lowest performing students in their courses. As the lead programmer, write a java program to achieve this. Your program should have the following features: Each correctly implemented feature earns you 3 marks. i. The program should make use of a sentinel to control the number of grades entered. ii. Total Number of grades entered iii. The average of the grades iv. Number of students that achieved a grade of 80 and above v. Number of students that achieved a grade of 50 and below
(ii) An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which these actions execute. Write an algorithm for the implementation of the sentinel control in Question A Sub Question I above.
(iii) For larger datasets, a linear search may be inadequate or perhaps inefficient. What other search method can be employed to return the maximum number from a set of elements in an array. Explain your answer.
import java.util.Scanner;
class Grade_record{
private String courseName;
// constructor
public Grade_record(String name){
courseName = name;
}
// setters
public void setCourseName(String name){
courseName = name;
}
//getters
public String getCourseName(){
return courseName;
}
// determine class average based on 10 user-entered grades
public void determineClassAverage(){
Scanner sc = new Scanner(System.in);
int total=0, gradeCounter=0, grade, above_eighty=0, below_fifty=0;
double average;
System.out.printf("Enter grade 1 or -1 to quit: ");
grade = sc.nextInt();
while(grade != -1)
{
if(grade >= 80) above_eighty++;
if(grade <= 50) below_fifty++;
total += grade;
gradeCounter++;
System.out.printf("Enter grade %d or -1 to quit: ", gradeCounter+1);
grade = sc.nextInt();
}
if(gradeCounter != 0){
average = (double)total / gradeCounter;
//display grades average
System.out.printf("\nTotal of the %d grades: %d\n", gradeCounter, total);
System.out.printf("Class average: %.2f\n", average);
System.out.printf("\nNumber of students below or eual to 50: %d", below_fifty);
System.out.printf("\nNumber of students above or eual to 80: %d", above_eighty);
}
}
}
public class My_class{
public static void main(String[] args){ Grade_record myGradeBook = new Grade_record("CS101 Introduction to Java Programming");
myGradeBook.determineClassAverage();
}
}
Comments
Leave a comment