F17 HW C5 6. In order to be allowed to compete in the end of season championship
ID: 3873636 • Letter: F
Question
F17 HW C5 6. In order to be allowed to compete in the end of season championship, an athlete must have achieved a winning record for the season. This means that the athlete must have come in first, second, or third in each of the five season events and come in first in at least one of the five events. Write a program that will input the athlete's name and his/her record in each of the five events (1%, 2nd,3d or DNQ) where DNQ means the athlete did not qualify in any of the top three positions in that event. Determine whether the athlete is eligible to compete in the championship and print the name of the athlete, whether eligible to compete, and giving the reason if the athlete is not eligible. For this problem, submit screen shots of your program code and your output. Check the logic of your code by running the program so that the output is "not eligible to compete" and the reason is that the athlete did not finish first in at least one event running the program so that the output is "not eligible to compete" and the reason is that the athlete failed to qualify in at least one race. - running the program so that the output is "eligible to compete" Py 0Explanation / Answer
package bookList;
import java.util.Arrays;
import java.util.Scanner;
public class Athlete {
private String athleteName;
private String[] seasonEvent;
public Athlete() {
}
public String getAthleteName() {
return athleteName;
}
public void setAthleteName(String athleteName) {
this.athleteName = athleteName;
}
public Athlete(String[] seasonEvent) {
super();
this.seasonEvent = seasonEvent;
}
public String atheleteStatus(){
int count=0;
for(int i=0;i<seasonEvent.length;i++){
if(seasonEvent[i].equals("1st")) count++;
if(seasonEvent[i].equalsIgnoreCase("DNQ")) return getAthleteName()+" is Not Eligible to compete,athlete failed to qualify in atleast one race.";
}
if(count==0) return getAthleteName()+"is Not Eligible to compete,athlete did not finish first in atleast one race.";
return getAthleteName()+" is Eligible to compete., ";
}
@Override
public String toString() {
return "Athlete [seasonEvent=" + Arrays.toString(seasonEvent) + "]";
}
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
System.out.println("Enter Athlete Name:");
String name=scn.next();
System.out.println("Enter Athlete Ranks in 5 seasons: ");
String[] ath=new String[5];
for(int i=0;i<5;i++){
ath[i]=scn.next();
}
Athlete athlete=new Athlete(ath);
athlete.setAthleteName(name);
//System.out.println(athlete);
System.out.println(Arrays.toString(athlete.seasonEvent));
String status=athlete.atheleteStatus();
String[] atheleteStatus=status.split(",");
System.out.println(atheleteStatus[0]);
System.out.println(atheleteStatus[1]);
}
}
/*
output: case1:
Enter Athlete Name:
Tarun
Enter Athlete Ranks in 5 seasons:
2nd 3rd 4th 5th 2nd
[2nd, 3rd, 4th, 5th, 2nd]
Tarun is Not Eligible to compete, athlete did not finish first in atleast one race.
case2 :
Enter Athlete Name:
Tarun
Enter Athlete Ranks in 5 seasons:
1st dnq 1st 2nd 3rd
[1st, dnq, 1st, 2nd, 3rd]
Tarun is Not Eligible to compete, athlete failed to qualify in atleast one race.
case3:
Enter Athlete Name:
Tarun
Enter Athlete Ranks in 5 seasons:
2nd 3rd 1st 4th 5th
[2nd, 3rd, 1st, 4th, 5th]
Tarun is Eligible to complete.
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.