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

For this project assignment, you are going to write a Java program to get total

ID: 3914233 • Letter: F

Question

For this project assignment, you are going to write a Java program to get total wins for a horse race. Project Specifications Each year, Christian Hur, the owner of Racine Horse Farms, enters four of his horses in five local horse races. He uses the table shown below to keep track of his horses' performances in each race. In the table, a "1" indicates that the horse won the race, a "2" indicates second place, and a "3" indicates third place. A "0" indicates that the horse did not finish in the top three places Christian wants an application that displays a summary of each horse's individual performance. Sample Race Results each column represents a race 1 2 3 4 5 10 1 0 3 2 2 1 0 2 0 3 0 3 01 each row represents a horse 43 2 1 0 0

Explanation / Answer

class HorseRace
{
public static void main (String[] args)
{
  int[][] race = new int[4][5];
  race = generateRuns();// initialize table
  
  int[] wins = new int[4];
  wins = calculateWins(race);
  
  displayResults(wins);
  
}

public static int[][] generateRuns()
{
int[][] race = {{0,1,0,3,2},{1,0,2,0,0},{0,3,0,1,0},{3,2,1,0,0}};
return race;
}

public static int[] calculateWins(int[][] race)// calculate wins for each horse
{
  int[] won = new int[4];
  
  for(int i=0;i<4;i++)
  {
   won[i] = 0;
   for(int j=0;j<5;j++)
   {
    if(race[i][j] == 1)// 1 indicates horse wins
    won[i]++;
   }
  }
  
  
  
  return won; // returns number of wins for each horse
}

public static void displayResults(int[] won)
{
  // display wins for each horse
  for(int i=0;i<4;i++)
  {
   System.out.println("Number of wins for horse "+(i+1)+" : "+ won[i]);
  }
}
}

Output:

Number of wins for horse 1 : 1
Number of wins for horse 2 : 1
Number of wins for horse 3 : 1
Number of wins for horse 4 : 1

Do ask if any doubt. Please upvote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote