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

In java write this program: Part 1: From scratch, create a program to... Read in

ID: 3882125 • Letter: I

Question

In java write this program:

Part 1: From scratch, create a program to... Read in Exam scores (assume 0-100) from the user until the user enters a negative number to end input. Once user input is complete, display the number of scores entered, the high score, the low score, and the class average, each on a separate lines. Reminder: Do NOT include the sentinel value (i.e. the negative exam score) as part of your data Part 2: You do NOT need to DEMO Part 1 before beginning Part 2, but make sure it works first! Assume the program will be used by a course with multiple sections (requires the use of a nested loop) Modify the program written in Part 1 so it now does the following (changes are in red): Ask the user for the Section Letter (e.g. A, B, C...) - Read in Exam scores (assume 0-100) for that section from the user until the users enters a negative number to end input. Once user input is complete, display the section letter, the number of scores entered, the high score, the low score, and the class average, each on a separate line for that section Ask the user if they want to enter scores for another section. If they do, repeat the above. Continue th until the user has entered in the info for all given sections of a course. Once all sections have been entered and the user has chosen to quit, display the highest overall score and the overall class average of all sections combined. is Hint: Declare one variable that holds the high score and total of all scores for a section (e.g. highSection / otalSection) and another to hold the high score and total for the entire class (e.g. highClasstotalClass)

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i

import java.util.Scanner;
public class ClassScores {
public static void main(String[] args) {
char section;
double score;
double lowSection, highSection, nSection, avgSection;
double lowClass = -1 , highClass = 0 , nClass = 0 , avgClass = 0;
Scanner keyboard = new Scanner(System.in);
String ans;
do
{
System.out.println("Enter a section letter (A, B,C ..): ");
section = keyboard.next().charAt(0);
System.out.println("Enter the scores for the section (enter -ve no. to stop):");
score = keyboard.nextDouble();
lowSection = -1;
highSection = 0;
nSection = 0;
avgSection = 0;
while(score > 0)
{
avgSection += score;
if(lowSection == -1 || score < lowSection)
lowSection = score;
if(score > highSection)
highSection = score;
nSection++;
score = keyboard.nextDouble();
}
//update for overall class including all sections
avgClass += avgSection;
nClass += nSection;
if(lowClass == -1 || lowSection < lowClass)
lowClass = lowSection;
if(highSection > highClass)
highClass = highSection;
//calculate section avg
if(nSection != 0)
avgSection /= nSection;
System.out.println("Section: " + section);
System.out.println("Low score: " + lowSection);
System.out.println("High score: " + highSection);
System.out.println("Section Avg: " + avgSection);
System.out.print("Do you want to enter another section? (y/n): ");
ans = keyboard.next().toLowerCase();
}while(ans.equals("y"));
avgClass /= nClass; //calculate class avg
System.out.println(" ========================= ");
System.out.println("Class Low score: " + lowClass);
System.out.println("Class High score: " + highClass);
System.out.println("Class Avg: " + avgClass);
}
}


output
=====
Enter a section letter (A, B,C ..):
A
Enter the scores for the section (enter -ve no. to stop):
60 70 80 90 95 -1
Section: A
Low score: 60.0
High score: 95.0
Section Avg: 79.0
Do you want to enter another section? (y/n): y
Enter a section letter (A, B,C ..):
B
Enter the scores for the section (enter -ve no. to stop):
67 78 89 90 -1
Section: B
Low score: 67.0
High score: 90.0
Section Avg: 81.0
Do you want to enter another section? (y/n): y
Enter a section letter (A, B,C ..):
C
Enter the scores for the section (enter -ve no. to stop):
54 58 96 70 85 70 -2
Section: C
Low score: 54.0
High score: 96.0
Section Avg: 72.16666666666667
Do you want to enter another section? (y/n): n
=========================
Class Low score: 54.0
Class High score: 96.0
Class Avg: 76.8

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