Hi, I'm new to Java and am having a problem getting my program to run, any help would be greatly appreciated. Here is the program:
//This program displays a message asking the user if they
//want to know the Top Premiership Players. If they say Yes,
//they will then be asked to enter a player number between 1-11.
//the program will then display which position the chosen number
//plays in, either Striker, Midfielder, Defender or Goalkeeper.
//The program will then display the names of the two Top Premiership
//players in the displayed position.The program will then ask the
//user to pick another player by number and repeat the program or
//chose No to end the program in which case the program will display Good bye.
[
import javax.swing.JOptionPane;
import java.awt.*;
public class TopPlayers {
public static void TopPlayerA ()//displays result to user
{
JOptionPane.showMessageDialog(null,"The top players in this position are Wanyne Rooney"+"\n Fernando Torres",
"TOP PLAYERS",JOptionPane.PLAIN_MESSAGE);
}
public static void TopPlayerB ()//displays result to user
{
JOptionPane.showMessageDialog(null,"The top players in this position are Frank Lampard"+"\n Cesc Fabrigas",
"TOP PLAYERS",JOptionPane.PLAIN_MESSAGE);
}
public static void TopPlayerC ()//displays result to user
{
JOptionPane.showMessageDialog(null,"The top players in this position are John Terry"+"\n Rio Ferdinand",
"TOP PLAYERS",JOptionPane.PLAIN_MESSAGE);
}
public static void TopPlayerD ()//displays result to user
{
JOptionPane.showMessageDialog(null,"The top players in this position are Petr Chec"+"\n Shay Given",
"TOP PLAYERS",JOptionPane.PLAIN_MESSAGE);
}
public static void WhichNumber()//ask the user to enter a shirt number
{
String number,Num;
int ShirtNumber,Position;
String i[]={"Striker","Midfield","Defender","Goalkeeper"};//use an array to hold names of positions
number = JOptionPane.showInputDialog("Enter a player number between 1-11");//ask user to enter player number
ShirtNumber=Integer.parseInt(number);
switch (ShirtNumber)
{
case 1://Striker
Num = JOptionPane.showInputDialog(null,"What Position"+ i[0]);//display telling
Position = Integer.parseInt(Num);
if (Position >=10)
{
JOptionPane.showMessageDialog(null,"Striker");
TopPlayerA();//calls method Top Payer A
}
else
{
JOptionPane.showMessageDialog(null,"Different Position"); }
break;
case 2://Midfielder
Num = JOptionPane.showInputDialog(null,"What Position"+ i[1]);//display telling
Position = Integer.parseInt(Num);
if (Position >=9)
{
JOptionPane.showMessageDialog(null,"Midfielder");
TopPlayerB();//calls method Top Payer B
}
else
{
JOptionPane.showMessageDialog(null,"Different Position");
}
break;
case 3://Defender
Num = JOptionPane.showInputDialog(null,"What Position"+ i[2]);//display telling
Position = Integer.parseInt(Num);
if (Position >=5)
{
JOptionPane.showMessageDialog(null,"Midfielder");
TopPlayerC();//calls method Top Payer C
}
else
{
JOptionPane.showMessageDialog(null,"Different Position");
}
break;
case 4://Goalkeeper
Num = JOptionPane.showInputDialog(null,"What Position"+ i[3]);
Position = Integer.parseInt(Num);
if (Position >=1)
{
JOptionPane.showMessageDialog(null,"Midfielder");
TopPlayerD();//calls method Top Payer D
}
else
{
JOptionPane.showMessageDialog(null,"Different Position");
}
break;
default:
JOptionPane.showMessageDialog(null,"There is only eleven players","ERROR",JOptionPane.ERROR_MESSAGE);
break;
}
}
public static void TryAgain()
{
int reply = JOptionPane.showConfirmDialog(null,"Try another number","TOP PLAYERS",JOptionpane.YES_NO_OPTION);
while (reply == JOptionPane.YES_OPTION)
WhichNumber();
{
JOptionPane.showMessageDialog(null,"Good bye","TOP PLAYERS",JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String args[])//main method
{
int answer = JOptionPane.showConfirmDialog(null,"Who are the top Premership players?",
"TOP PLAYERS",JOptionPane.YES_NO_OPTION);//ask user if the want to know
if (answer == JOptionPane.YES_OPTION)//control structure
{
WhichNumber();//calls method
TryAgain();
}
else
{ JOptionPane.showMessageDialog(null,"Good bye","TOP PLAYERS",JOptionPane.INFORMATION_MESSAGE);
System.exit (0);//terminate program
}
}
]