I am having a lot of trouble. I have a new teacher and the class is a lot different. Here is the problem:
Write a class named HorseRace. The HorseRace class should have two parallel arrays: one called names for the names of the horses and one called position for the position of the horses. The program should ask the user for the number of horses in the race and the names of the horses. The names of the horses should be stored in the names array. All the horses should be the race at position zero so the position array should be initialized to 0. After all the names have been entered, the race begins.
The race is run by adding a random integer between 1 and 5 to each horse’s position. The race ends when all of the horses cross the finish line (reach or exceed position 100). You should model the race using a loop and each horse should be processed using a loop as well.
The program should output:
1. The winner of the race should be output, example: “Secretariat wins!”
2. The name of each of the non-winning horses should be output when it crosses the finish line, example: “Man o’ War crosses the finish line!”
Here is what I have but I can't get past the errors:
import java.util.Scanner ;
import java.util.Math;
class HorseRace {
public static void main (String args []){
int i=0,j,k,t,flag=0,k1=0;
Scanner input = new Scanner(System.in);
System.out.println("Enter number of Horses : ");
int number = input.nextInt();
int position[] = new int[number];
int match[] = new int[number];
String name[] = new String[number] ;
for(i=0;i<number;i++){
System.out.println("Enter name of Horse : ");
name[i]=input.toString();
position[i]=0;
}
for(i=0;i<number;i++){
}
for(j=0;j<number;i++){
}
for(t=0;t<=k1;t++){
}
if (j !=match[t]){
number=(Math.random() * 4)+1;
if(number>=100){
}
if(flag==0){
System.out.println("Wins" +name[i]);
flag=1;
match[k1]=i; k1++;
}
else{
System.out.println(name[i]+"’ War crosses the finish line ");
match[k1]=i; k1++;}
}
}
}