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

how do I begin to make a java program that tracks the scores of soccer games and

ID: 3744616 • Letter: H

Question

how do I begin to make a java program that tracks the scores of soccer games and determines the winner?

user is prompted to enter the names for the home and visiting teams.

user enters the score for the home team first half and then the score for the visiting team

user is prompted to enter second half scores

After the scores are entered, the final score will be calculated

If the game is tied, the user will be prompted to enter the score for the overtime

Only one goal is allowed in the overtime

Following the overtime (if required), the program displays the results of the game

prompted to enter the names for the home and visiting teams.

user enters the score for the home team first half and then the score for the visiting team

user is prompted to enter second half scores

After the scores are entered, the final score will be calculated

If the game is tied, the user will be prompted to enter the score for the overtime

Only one goal is allowed in the overtime

Following the overtime (if required), the program displays the results of the game

Explanation / Answer

Soccer.java

//import for taking input
import java.util.Scanner;
//driver class
public class Soccer {
//main function to execute class
public static void main(String[] args) {
//variable declaration
int hostGoal=0,visitorGoal=0;
String hostName,visitorName;
//Creating object of scanner to take input from the user
Scanner inp=new Scanner(System.in);
//asking user for host team name
System.out.print("Enter host team name =");
//storing name of the host team
hostName=inp.nextLine();
//asking user for visiting team name
System.out.print("Enter visiting team name =");
//storing name of the host team
visitorName=inp.nextLine();
//asking user for half time score
System.out.print("Enter "+hostName+" team half time score =");
//storing score for the host team
hostGoal=inp.nextInt();
//asking user for half time score
System.out.print("Enter "+visitorName+" team half time score =");
//storing score for the host team
visitorGoal=inp.nextInt();
System.out.println("Half time score is "+hostName+" "+hostGoal+" "+visitorName+" "+visitorGoal);
//asking user for full time score for host
System.out.print("Enter "+hostName+" team second half score =");
//storing score for the host team
hostGoal=hostGoal+inp.nextInt();
//asking user for full time score for visitor
System.out.print("Enter "+visitorName+" team second half score =");
//storing score for the host team
visitorGoal=visitorGoal+inp.nextInt();
//showing the final score to the user
System.out.println("Full time score is "+hostName+" "+hostGoal+" "+visitorName+" "+visitorGoal);
//checking for the result of the game
if(hostGoal>visitorGoal){//goals scored by host team is more than visitors
System.out.println(hostName+" team won the match by "+hostGoal+"-"+visitorGoal);//host team won the match
}
else if(hostGoal<visitorGoal){//goals scored by visitor team is more than host
System.out.println(visitorName+" team won the match by "+visitorGoal+"-"+hostGoal);//visitor won the match   
}
else{//golas scored by host and the visitors are equal
System.out.println("Overtime score");//ask for the overtime score
System.out.print("Which team score the first goal? 1. Host 2. Visitor= ");//check if which team scored the first goal
int team=inp.nextInt();//taking the input to calculate the result
if(team==1){//if the goal is scored by the host team
hostGoal=hostGoal+1;//increase number of goal by 1
System.out.println(hostName+" team won the match by "+hostGoal+"-"+visitorGoal);//display the result
}
else{//if the goal is scored by the visitor team
visitorGoal=visitorGoal+1;//increase number of goal by 1
System.out.println(visitorName+" team won the match by "+visitorGoal+"-"+hostGoal);//display the result
}
}
  
}
}

Output:

run:
Enter host team name =Team1
Enter visiting team name =Team2
Enter Team1 team half time score =2
Enter Team2 team half time score =3
Half time score is
Team1 2
Team2 3
Enter Team1 team second half score =1
Enter Team2 team second half score =2
Full time score is
Team1 3
Team2 5
Team2 team won the match by 5-3

Enter host team name =New York
Enter visiting team name =Washington
Enter New York team half time score =2
Enter Washington team half time score =4
Half time score is
New York 2
Washington 4
Enter New York team second half score =2
Enter Washington team second half score =0
Full time score is
New York 4
Washington 4
Overtime score
Which team score the first goal? 1. Host 2. Visitor= 2
Washington team won the match by 5-4