Question

This program is going to compare the scores of two volleyball teams that play each other. To win a match in volleyball a team must get 25 points. But they must also win by 2. So even if a team reaches 25 that game continues until one team is ahead by 2 points. Let’s assume that these two teams are going to play 5 matches.

This program should accept from the user the scores for each team one match at a time. If at any time that user enters scores that violate the 25 point rule or the “win by 2” point rule, print an error on the screen and make the user enter both scores again.

When the user is finished entering the scores, the program should print which team won the game. This is the team that won the most matches.

You have to use arrays and loops in this program.

You can do a File | Export | Export to Zip and it will create a ZIP file of the application. Export the application this way to turn in during the first week of class.

Sample Output: In italic is what the user entered.

Sample Output 1
Welcome to the volleyball score program.
Enter the number of points Team 1 got in Match 1
10
Enter the number of points Team 2 got in Match 1
25
Enter the number of points Team 1 got in Match 2
1
Enter the number of points Team 2 got in Match 2
25
Enter the number of points Team 1 got in Match 3
23
Enter the number of points Team 2 got in Match 3
25
Enter the number of points Team 1 got in Match 4
10
Enter the number of points Team 2 got in Match 4
25
Enter the number of points Team 1 got in Match 5
0
Enter the number of points Team 2 got in Match 5
25
Team 2 has won the game.


Sample Output 2
Welcome to the volleyball score program.
Enter the number of points Team 1 got in Match 1
10
Enter the number of points Team 2 got in Match 1
24
That can’t be. One team must get at least 25 points. Please reenter the data.
Enter the number of points Team 1 got in Match 1
10
Enter the number of points Team 2 got in Match 1
25
Enter the number of points Team 1 got in Match 2
1
Enter the number of points Team 2 got in Match 2
25
Enter the number of points Team 1 got in Match 3
23
Enter the number of points Team 2 got in Match 3
25
Enter the number of points Team 1 got in Match 4
10
Enter the number of points Team 2 got in Match 4
25
Enter the number of points Team 1 got in Match 5
24
Enter the number of points Team 2 got in Match 5
25
That can’t be. One team must win by 2 points. Please reenter the data.
Enter the number of points Team 1 got in Match 5
24
Enter the number of points Team 2 got in Match 5
26
Team 2 has won the game.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;

public class ScoreTracker {

public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int score1, score2, wins1 = 0, wins2 = 0;

System.out.println("Welcome to the volleyball score program.");
for(int i = 0; i < 5; i++)
{
System.out.println("Enter the number of points Team 1 got in Match " + (i+1));
score1 = input.nextInt();
System.out.println("Enter the number of points Team 2 got in Match " + (i+1));
score2 = input.nextInt();

if(Math.abs(score1-score2) < 2 || (score1 < 25 && score2 < 25))
{
System.out.println("Score error: scores must differ by at least 2 points and one team must have at least 25 points");
i = i-1;
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Personal Name List in Java
Homework Solution
$8.00
Java
Programming
Computer Science
Codes
Algorithms
Personal Name List
Records
Errors
Arrays
Items
Variables
Statements
Characters
Moving Elements
Input
Output
Java Problems: Euclidean Distance and Arrays
Homework Solution
$20.00
Java
Programming
Computer Science
Coding
Euclidean Distance
Reversing an Array
String Values
Integer Values
Boolean Arrays
Input
Output
Square Root
Sum of Squares
Mathematics
Vectors
Rows
Columns
Class Money in Java
Homework Solution
$20.00
Java
Programming
Coding
Money
UML Diagram
Computer Science
Dollars
Cents
Parameters
Statements
Methods
Strings
Integers
Finance
Arithmetic Operations
Cylinder Containers in Java
Homework Solution
$25.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Geometry
Mathematics
Cylinder
Radius
Finance
Costs
Containers
Companies
Functions
Get help from a qualified tutor
Live Chats