Created
March 23, 2015 19:42
-
-
Save khatchad/44cfb81cdf01659bb953 to your computer and use it in GitHub Desktop.
This program calculates the total number of points a soccer team has earned over a series of games. The user enters a series of point values, then -1 when finished.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; // Needed for the Scanner class | |
/** | |
This program calculates the total number of points a | |
soccer team has earned over a series of games. The user | |
enters a series of point values, then -1 when finished. | |
*/ | |
public class SoccerPoints | |
{ | |
public static void main(String[] args) | |
{ | |
int points; // Game points | |
int totalPoints = 0; // Accumulator initialized to 0 | |
// Create a Scanner object for keyboard input. | |
Scanner keyboard = new Scanner(System.in); | |
// Display general instructions. | |
System.out.println("Enter the number of points your team"); | |
System.out.println("has earned for each game this season."); | |
System.out.println("Enter -1 when finished."); | |
System.out.println(); | |
// Get the first number of points. | |
System.out.print("Enter game points or -1 to end: "); | |
points = keyboard.nextInt(); | |
// Accumulate the points until -1 is entered. | |
while (points != -1) | |
{ | |
// Add points to totalPoints. | |
totalPoints += points; | |
// Get the next number of points. | |
System.out.print("Enter game points or -1 to end: "); | |
points = keyboard.nextInt(); | |
} | |
// Display the total number of points. | |
System.out.println("The total points are " + | |
totalPoints); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment