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

JAVA PROJECT use GUI input/output You are a sports fanatic. Create a one dimensi

ID: 642354 • Letter: J

Question

JAVA PROJECT

use GUI input/output

You are a sports fanatic. Create a one dimensional String array to input your favorite sports. Ask the user to input the size of the array by asking them how many sports they will enter. Display to the user an error if they entered a duplicate sport; if the value is unique store in the array. Display the sports in the array out to the user at the end of entering all of the values. Use an enhanced for statement to output the total number of array elements to the user. Use the predefined class discussed in class to sort the array and output to the user. Create two .java classes, one with you main class that calls an object of the second class. .

Explanation / Answer

import java.io.*;


class SportsDetails
{
void setData(String sports[],int length)
{

try {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

for(int j=0;j {
sports[j]=br.readLine();   
}
}
catch(Exception e){System.out.println(e);}
}

void getData(String[] s,int length)
{

for(int i=0;i System.out.println(s[i]);
}

int compare(String[] s)
{
int count=0;

for(int i=0;i {
for(int k=0;k {
if(s[i].equals(s[k]))
count++;
}}
return count;   
}   
  
}
  

class SportsMain
{
public static void main(String atgs[])
{
try
{
System.out.println("ENter No of sports would Like to enter:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i=Integer.parseInt(br.readLine());
String sports[]=new String[i];
int check=0;
  
SportsDetails sp=new SportsDetails();
sp.setData(sports,i);
check=sp.compare(sports);

if(check>0)
{
System.out.println("Please Enter Different Sports");
sp.setData(sports,i);
}
sp.getData(sports,i);
}
catch(Exception e){System.out.println(e);}
}

}