Hi, I'm a beginner with Java and I need help with an assignment:
Write a program that will help the Toronto Blue Jay's scouts decide which players they should draft next year. For each player the scouts have been watching, a record has been prepared showing the player's name, age, position, and batting average. Design a program that will ask the scout to enter information for 10 players into arrays. The program should then check each of the players and display statistics of only those players who are under 25 years old and have a batting average of .280 or better. Display the players that qualify sorted by their age.
A menu is required that has the following options:
Enter Blue Jay Data
Display possible Draft Choices
Exit Program
I'm having trouble with having the program only display batters under 25 years of age and a batting average above or equal to .280.
public class Bluejays3
{
static Console c;
static String name[] = new String [11];
static double bataverage[] = new double [11];
static int age[] = new int [11];
static String position[] = new String [11];
static int x;
public static void main (String[] args)
{
c = new Console (); //Opens the console.
int choice;
do
{
c.print (" Main Menu\n");
c.print (" *********\n");
c.print (" 1. Enter Blue Jay Data");
c.print ("\n 2. Display Possible Draft Choices");
c.print ("\n 3. Exit");
c.print ("\n Select your choice 1-3: ");
choice = c.readInt ();
if (choice == 1)
Batterdata (); //opens data entry method
if (choice == 2)
Searchscouts (); //opens search method
if (choice == 3)
{
c.print ("\nGoodbye!"); //exits program
}
else if (choice < 1 || choice > 3)
{
c.clear ();
c.print ("Invalid Number, try again!\n\n"); //user must enter a proper value or this displays
}
}
while (choice != 3);
}
public static void Batterdata ()
{
c.print ("You will need to enter 10 possible draft choices\n");
for (x = 1 ; x <= 10 ; x++) //loops for values (0-9) User must enter data for 0-9.
{
c.print ("\nPlease enter the name of batter number " + x + ":");
name [x] = c.readLine ();
c.print ("Please enter this batters batting average (ex .300): ");
bataverage [x] = c.readDouble ();
c.print ("Please enter this batters position: ");
position [x] = c.readLine ();
c.print ("Please enter this batters age: ");
age [x] = c.readInt ();
}
}
public static void Searchscouts ()
{
{
c.clear ();
int smallest, i, temp;
boolean found;
c.print ("Possible Draft Choices\n\n");
for (x = 1 ; x <= 10 ; x++)
{
smallest = x;
for (i = x ; i <= 10 ; i++)
{
while(age [i] < age [smallest])
smallest = i;
}
temp = age [x];
age [x] = age [smallest];
age [smallest] = temp;
}
for (x = 1 ; x <= 10 ; x++)//This is the problem,what can i do to change this so that is only displays batters younger than 25 and with an average of .280 or more?
{
c.println ("Name " + name[x] + " Age: " + age [x] + " Position: " + position[x] + " Batting Average: " + bataverage[x]);
}
}
}
}
The problem is in the Searchscouts() method, any help is greatly appreciated, and please remember im a beginner so if you could explain your process I would be very thankful! :)