Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I keep getting this error while trying to run my java code. Please help me fix: import java.util.ArrayList; import java.util.Scanner; public class CMSC 2 1
I keep getting this error while trying to run my java code. Please help me fix: import java.util.ArrayList;
import java.util.Scanner;
public class CMSCPROJNW
class Height
private final int feet;
private final int inches;
public Heightint feet, int inches
this.feet feet;
if inches
this.inches inches ;
this.feet inches ;
else
this.inches inches;
public int toInches
return feet inches;
@Override
public String toString
return feet inches ;
class Player
private final String name;
private final Height height;
private final int age;
public PlayerString name, Height height, int age
this.name name;
this.height height;
this.age age;
public String getName
return name;
public Height getHeight
return height;
public int getAge
return age;
@Override
public String toString
return "Name: name Height: height.toString Age: age;
class InputData
public static void mainString args
Scanner scanner new ScannerSystemin;
ArrayList players new ArrayList;
while true
System.out.printEnter player name or done to finish: ;
String name scanner.nextLine;
if nameequalsIgnoreCasedone
break;
System.out.printEnter height feet: ;
int feet scanner.nextInt;
System.out.printEnter height inches: ;
int inches scanner.nextInt;
System.out.printEnter age: ;
int age scanner.nextInt;
scanner.nextLine; Consume newline
players.addnew Playername new Heightfeet inches age;
int totalAge ;
for Player player : players
totalAge player.getAge;
double averageAge totalAge double players.size;
Player tallestPlayer null;
for Player player : players
if playergetAge averageAge
if tallestPlayer null player.getHeighttoInches tallestPlayer.getHeighttoInches
tallestPlayer player;
System.out.printlnAverage age of all players: averageAge;
if tallestPlayer null
System.out.printlnTallest player whose age is less than or equal to the average age: tallestPlayer;
else
System.out.printlnNo player found whose age is less than or equal to the average age.";
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started