Modify the Test Score application so that it uses Big Decimal arithmetic to calculate the average test score with result rounded to 1 decimal place. Note that because the scoreCount and scoreTotal are int, you don’t have to create the Big Decimal object from strings. import java.util.Scanner; 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 <= 100) { // 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; } } // display the score count, score total, and average score double averageScore = scoreTotal / scoreCount; String message = "n" + "Score count:   " + scoreCount + "n" + "Score total:   " + scoreTotal + "n" + "Average score: " + round(averageScore,1) + "n"; System.out.println(message); }

The provided code is a Java program that calculates the average test score based on user input. The task is to modify the program to use Big Decimal arithmetic and round the result to one decimal place.

Here is the modified code:

“`java
import java.math.BigDecimal;
import java.util.Scanner;

public class TestScore {
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
BigDecimal scoreTotal = BigDecimal.ZERO;
int scoreCount = 0;
int testScore = 0;
Scanner sc = new Scanner(System.in);

// get a series of test scores from the user
while (testScore <= 100) { // get the input from the user System.out.print("Enter score: "); testScore = sc.nextInt(); // accumulate score count and score total if (testScore <= 100) { scoreCount++; scoreTotal = scoreTotal.add(BigDecimal.valueOf(testScore)); } } // calculate and display the score count, score total, and average score BigDecimal averageScore = scoreTotal.divide(BigDecimal.valueOf(scoreCount), 1, BigDecimal.ROUND_HALF_UP); String message = "n" + "Score count: " + scoreCount + "n" + "Score total: " + scoreTotal + "n" + "Average score: " + averageScore + "n"; System.out.println(message); } } ``` In this modified code, the following changes were made: 1. The `BigDecimal` class is imported to use Big Decimal arithmetic. 2. The `scoreTotal` variable is initialized as `BigDecimal.ZERO` instead of `double` to ensure accurate decimal arithmetic. 3. The `divide` method of `BigDecimal` is used instead of the division operator to calculate the average score. The third argument of the `divide` method is used to specify the rounding mode, with `BigDecimal.ROUND_HALF_UP` rounding the result to the nearest digit, or up if it's exactly halfway. 4. The `round` method, which was not provided in the original code, is not necessary in this modified version as the `divide` method already rounds the result. With these modifications, the program now correctly uses Big Decimal arithmetic and rounds the average score to one decimal place.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer