In: Computer Science
Write a complete program in java that will do the following:
Sports: Baseball, Basketball, Football, Hockey, Volleyball, Waterpolo
Players: 9, 5, 11, 6, 6, 7
Store the data in appropriate arrays
Provide an output of sports and player numbers. See below:
Baseball 9 players.
Basketball 5 players.
Football 11 players.
Hockey 6 players.
Volleyball 6 players.
Waterpolo 7 players.
Use Scanner to provide the number of friends you have for a team sport.
Provide an output of suggested sports for your group of friends. If your group is 6 people, see the example below:
Your group has 6 people. Here is/are the suggested team sport(s):
Basketball needs 5 players.
Hockey needs 6 players.
Volleyball needs 6 players.
If your group is less than 5 people, see the example below:
Your group has less than 5 people. There is no suggested team sport.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int member[]=new int[]{9,5,11,6,6,7};
String sport[]=new String[]{"Baseball","Basketball","Football","Hockey","Volleyball","Waterpool"};
for(int i=0;i<6;i++)
{
System.out.println(sport[i]+" "+member[i]+" players"); }
System.out.println("\n\n");
int count;
int flag=0;
System.out.print("Enter total number of people in your group:");
count=in.nextInt();
if(count>=5)
{
System.out.println("Your group has "+ count+" players. Here is/are the suggested team sport(s)");
for(int i=0;i<6;i++)
{
if(member[i]<=count)
{
System.out.println(sport[i]+" needs "+ member[i]+" players");
flag=1; } }}
else
System.out.println("Your group has less than 4 players. There is no suggested team sport.");
}
}
please upvote... I need it.. Thanks