pclovechristian

Score Count

Sep 5th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. Import java.util.Scanner;
  2. public class TestScoreApp
  3.     {
  4.         public static void main(String[] args)
  5.             {
  6.             System.out.println("Please enter test scores that range from 0 to 100.");
  7.             System.out.println("To end the program enter 999.");
  8.             System.out.println(); // print a blank line
  9.             // initialize variables and create a Scanner object
  10.  
  11.             double scoreTotal = 0.0;
  12.             int scoreCount = 0;
  13.             int testScore = 0;
  14.  
  15.             Scanner sc = new Scanner(System.in);
  16.  
  17.             while (testScore !=999) // get a series of test scores from the user
  18.                  {
  19.                     System.out.print("Enter score: "); // get the input from the user
  20.                     testScore = sc.nextInt();
  21.  
  22.                     if (testScore <= 100) // accumulate score count and score total
  23.                         {
  24.                             scoreCount = scoreCount + 1;
  25.                             scoreTotal = scoreTotal + testScore;
  26.                         }
  27.                         else if (testScore >100) // if user put more than 100, it will print out "Invalid entry, not counted."
  28.                             {
  29.                             System.out.println("Invalid entry, not counted");
  30.                             }
  31.  
  32.                 }
  33.             // display the score count, score total, and average score
  34.             double averageScore = scoreTotal / scoreCount;
  35.             String message = "\n"
  36.             + "Score count: " + scoreCount + "\n"
  37.             + "Score total: " + scoreTotal + "\n"
  38.             + "Average score: " + averageScore + "\n";
  39.               System.out.println(message);
  40.         }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment