Purchase Solution

Java code for NumberFormat class

Not what you're looking for?

Ask Custom Question

Need to add in:

The number format in one decimal place to make this to round the average score to one decimal in this program.

////////////////////////////////////////////////

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 <= 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: " + averageScore + "n";
System.out.println(message);
}
}.

Purchase this Solution

Solution Summary

Java code for NumberFormat class is utilized in the solution.

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Javscript Basics

Quiz on basics of javascript programming language.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.