-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoccerPoints.java
48 lines (37 loc) · 1.32 KB
/
SoccerPoints.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//SoccerPoints.java
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 number of points.
System.out.println("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 number of points.
System.out.println("Enter game points or -1 to end: ");
points = keyboard.nextInt();
}
// Display the total number of points.
System.out.println("The total points are " +
totalPoints);
}
}