Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that computes the overall numeric grade for each student in a cl

ID: 3588149 • Letter: W

Question

Write a program that computes the overall numeric grade for each student in a class. The program should begin by asking the user several questions about the class as a whole as follows. First, the program should prompt the user to enter the number of tests that were given in the class. If the user specifies that fewer than two tests were given in the class, the program should display an error message and continue prompting (and if necessary, printing error messages) until a valid input is given. Next, the program should ask the user whether the lowest test score should be dropped when computing each student’s overall numeric grade. Then the program should prompt the user to enter the maximum test score considered valid. Next, the program should prompt the user to enter the name of the current student or Q or q to quit. The program should then prompt the user to enter each test score for the current student (referring to the current student by name). If a negative value or a value exceeding the maximum valid test score is entered, the program should display an error message and continue prompting (and if necessary, printing error messages) until a valid input is given. Once the user has entered the specified number of valid test scores for the current student, the program should report the current student’s overall numeric grade as the average of the student’s test scores (rounded to two decimal places) after dropping the current student’s lowest test score if the user specified this procedure for the class. The program should then continue by once again prompting the user to enter the name of the current student or Q or q to quit, etc.

Explanation / Answer

import java.math.BigDecimal;

import java.math.RoundingMode;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

import java.util.Scanner;

public class Core {

public static void main(String[] args) {

List<Integer> test_scores;

Scanner sc=new Scanner(System.in);  

System.out.println("Please enter the number of tests given in the class");  

int no_exams=sc.nextInt();

while(no_exams < 2){

System.out.println("The number of tests should be greater than or equal to 2, Please re-enter");  

no_exams=sc.nextInt();

}

  

System.out.println("Would you like to drop the lowest score of the student, please enter Y/N");

String drop_low_score = sc.next();

System.out.println("Please enter the maximum test score allowed");

int max_test_score = sc.nextInt();

String student_name = "";

do {

test_scores = new ArrayList<Integer>();

System.out.println("please enter the name of the current student or Q or q to quit");

student_name = sc.next();

if(student_name.equalsIgnoreCase("Q")) {

System.exit(0);

}

System.out.println("Please Enter the Scores for the Student "+ student_name);

for(int i=0;i<no_exams;i++) {

int test_score = sc.nextInt();

while(test_score < 0 || test_score > max_test_score) {

System.out.println("Please Enter the test score in the range of 0 to max score allowed");

test_score = sc.nextInt();

}

test_scores.add(test_score);

System.out.println(test_scores);

}

if(drop_low_score.equalsIgnoreCase("Y")) {

test_scores.remove(test_scores.indexOf(Collections.min(test_scores)));

}

double integer_grade = calculateAverage(test_scores);

System.out.println("Final Grade of the Student "+student_name+" is "+integer_grade);

}while(!student_name.equalsIgnoreCase("Q"));   

}

public static double calculateAverage(List<Integer> test_scores) {

int sum = 0;

double average = 0.00;

double no_test = test_scores.size();

for (Integer test_score : test_scores) {

sum = sum + test_score;

}

average = sum / no_test;

BigDecimal rounded_avg = new BigDecimal(average);

rounded_avg = rounded_avg.setScale(2, RoundingMode.HALF_UP);

return rounded_avg.doubleValue();

}

}

Please let me know in case you need more details about the program.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote