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

Need help starting this problem . import java.util.Scanner; public class TestSco

ID: 3662825 • Letter: N

Question

Need help starting this problem .

import java.util.Scanner;

public class TestScoreApp
{
    public static void main(String[] args)
    {
        // display operational messages
        System.out.println("Please enter test scores that range from 0 to 100.");
        System.out.println("To end the program enter 999.");
        System.out.println(); // print a blank line

        // initialize variables and create a Scanner object
        double scoreTotal = 0;
        int scoreCount = 0;
        int testScore = 0;
        Scanner sc = new Scanner(System.in);

        // get a series of test scores from the user
        while (testScore != 999)
        {
            // get the input from the user
            System.out.print("Enter score: ");
            testScore = sc.nextInt();

            // accumulate score count and score total
            if (testScore <= 100)
            {
                scoreCount = scoreCount + 1;
                scoreTotal = scoreTotal + testScore;
            }
            else if (testScore != 999)
                System.out.println("Invalid entry, not counted");
        }

        // display the score count, score total, and average score
        double averageScore = scoreTotal / scoreCount;
        String message = " " +
                         "Score count:   " + scoreCount + " "
                       + "Score total:   " + scoreTotal + " "
                       + "Average score: " + averageScore + " ";
        System.out.println(message);
    }
}

1.use the += operator to increase the scorecount and score total variables then, test this to make sure that it works.

2. As the user enters test scores, use the methods of the math class to keep track of the minimum and maximum scores. When the user enters 999 to end the program, display these scores at the end of the other output data. Now, test these changes to make sure they work.

3. change the variable that you use to total the scores from a double to an int data type. Then, use casting to cast the score count and score total to doubles as you calculate the average score and save that average as a double. Now, test the change.

4. Use the NumberFormat class to round the average score to one decimal place before displaying it at the end of the program. Then test this change.

Explanation / Answer


package score;

import java.util.Scanner;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
//import java.lang.System;

public class Score {

DecimalFormat df = new DecimalFormat("#.####");
int max=0,min=0;
Score(){
System.out.println("Please enter test scores that range from 0 to 100.");
  
System.out.println("To end the program enter 999.");
System.out.println();
int scoreTotal = 0;
double scoreCount = 0;
double testScore = 0;
  
Scanner sc = new Scanner(System.in);
  
while(testScore != 999)
{
// get the input from the user
System.out.print("Enter score: ");

testScore = sc.nextInt();

// accumulate score count and score total
if ((int)(testScore) <= 100)
{
if(max<=(int)(testScore) && (int)(testScore)!= 999)
{   
  
max=(int)(testScore);
  
}
/*else if(min>=testScore && testScore != 999)
{
min=testScore;
}*/
scoreCount +=1;
scoreTotal += testScore;
}
else if (testScore != 999)
System.out.println("Invalid entry, not counted");
}

// display the score count, score total, and average score
df.setRoundingMode(RoundingMode.CEILING);

double averageScore = scoreTotal / scoreCount;
String message = " " +
"Score count: " + scoreCount + " "
+ "Score total: " + scoreTotal + " "
+ "Average score: " + (df.format(averageScore)) + " ";
//System.out.println(max);
System.out.println(message+"max = "+max);
}
public static void main(String[] args) {
  
Score s=new Score();
}
  
}