Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import java.util.Scanner;
- public class TestScoreApp
- {
- public static void main(String[] args)
- {
- 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.0;
- int scoreCount = 0;
- int testScore = 0;
- Scanner sc = new Scanner(System.in);
- while (testScore !=999) // get a series of test scores from the user
- {
- System.out.print("Enter score: "); // get the input from the user
- testScore = sc.nextInt();
- if (testScore <= 100) // accumulate score count and score total
- {
- scoreCount = scoreCount + 1;
- scoreTotal = scoreTotal + testScore;
- }
- else if (testScore >100) // if user put more than 100, it will print out "Invalid entry, not counted."
- {
- System.out.println("Invalid entry, not counted");
- }
- }
- // 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment