Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 5. If they choose “soccer”, have a 50% chance a riot happens shown after th

ID: 3777203 • Letter: P

Question

Part 5. If they choose “soccer”, have a 50% chance a riot happens shown after the display information. You cannot use the “choice” variable to determine this nor put it inside the displayInformation() method.
Example 1 (user input is bold): What sport do you wish to see information about?

The options are: football, soccer or tennis soccer

Area played in: 7000

Game duration: 90

Number of players: 11

Points per score: 1

Substitutions: 3
Example 2 (user input is underlined): What sport do you wish to see information about? The options are: football, soccer or tennis soccer

Area played in: 7000

Game duration: 90

Number of players: 11

Points per score: 1

Substitutions: 3

People are rioting in the streets!

Here's the classes (Main)

import java.util.Scanner;

public class Main {
  
public static void main(String[] args)
{
System.out.println("What sport do you wish to see information about?");
System.out.println("The options are: football, soccer or tennis");
  
Scanner input = new Scanner(System.in);
String choice = input.nextLine();
  
if(choice.equalsIgnoreCase("football"))
{
Football game = new Football();
game.displayInformation();
}
else if(choice.equalsIgnoreCase("soccer"))
{
Soccer game = new Soccer();
game.displayInformation();
game.loseBigGame();
}
else if(choice.equalsIgnoreCase("tennis"))
{
Tennis game = new Tennis();
game.displayInformation();
}
}
}

football

public class Football {
private int area;
private int commercialTime;
private int duration;
private int numberOfPlayers;
private int secondaryScoreAmount;
private int scoreAmount;
private int toDown;
  
public Football()
{
area = 5000;
commercialTime = 60;
duration = 60;
numberOfPlayers = 11;
secondaryScoreAmount = 3;
scoreAmount = 7;
toDown = 10;
}
  
public void score()
{
System.out.println("Touchdown!");
}
  
public void secondaryScore()
{
System.out.println("Field goal!");
}
  
public void displayInformation()
{
System.out.println("Area played in: "+area);
System.out.println("Commercial duration: "+commercialTime);
System.out.println("Game duration: "+duration);
System.out.println("Number of players: "+numberOfPlayers);
System.out.println("Points per score: "+scoreAmount);
System.out.println("Points per secondary score: "+secondaryScoreAmount);
System.out.println("Until first down: "+toDown);
}
  
  
}

Tennis

public class Tennis {
  
private int area;
private int matches;
private int numberOfPlayers;
private int scoreAmount;
private int sets;
private boolean toServe;

public Tennis()
{
area = 195;
matches = 3;
numberOfPlayers = 1;
scoreAmount = 1;
sets = 6;
toServe = true;
}
  
public void score()
{
System.out.println("Point!");
}
  
public void displayInformation()
{
System.out.println("Area played in: "+area);
System.out.println("Number of matches: "+matches);
System.out.println("Number of players: "+numberOfPlayers);
System.out.println("Points per score: "+scoreAmount);
System.out.println("Points per sets: "+sets);
}
  
}

Soccer

ublic class Soccer {
private int area;
private int duration;
private int numberOfPlayers;
private int scoreAmount;
private int substitutions;
private boolean toRiot;
  
public Soccer()
{
area = 7000;
duration = 90;
numberOfPlayers = 11;
scoreAmount = 1;
substitutions = 3;
toRiot = false;
}
  
public void score()
{
System.out.println("Goal!");
}
  
public void displayInformation()
{
System.out.println("Area played in: "+area);
System.out.println("Game duration: "+duration);
System.out.println("Number of players: "+numberOfPlayers);
System.out.println("Points per score: "+scoreAmount);
System.out.println("Substitutions: "+substitutions);
}
  
public void loseBigGame()
{
if(Math.random() > 0.5)
{
System.out.println("People are rioting in the streets!");
toRiot = true;
}
}
}

Explanation / Answer

No modification was needed. Just added a display statement to check the random value.. you can comment it.

PROGRAM CODE:

package Sample;

public class Soccer {
private int area;
private int duration;
private int numberOfPlayers;
private int scoreAmount;
private int substitutions;
private boolean toRiot;
  
public Soccer()
{
area = 7000;
duration = 90;
numberOfPlayers = 11;
scoreAmount = 1;
substitutions = 3;
toRiot = false;
}
  
public void score()
{
System.out.println("Goal!");
}
  
public void displayInformation()
{
System.out.println("Area played in: "+area);
System.out.println("Game duration: "+duration);
System.out.println("Number of players: "+numberOfPlayers);
System.out.println("Points per score: "+scoreAmount);
System.out.println("Substitutions: "+substitutions);
}
  
public void loseBigGame()
{
   double random = Math.random();
   //added this code to view the chance each time.. the proivded code works perfectly
   System.out.println("Chance:" + random*100);
if(random > 0.5)
{
System.out.println("People are rioting in the streets!");
toRiot = true;
}
}
}

OUTPUT:

What sport do you wish to see information about?
The options are: football, soccer or tennis
soccer
Area played in: 7000
Game duration: 90
Number of players: 11
Points per score: 1
Substitutions: 3
Chance:87.48687592274469
People are rioting in the streets!