Do you need this or any other assignment done for you from scratch?
We have qualified writers to help you.
We assure you a quality paper that is 100% free from plagiarism and AI.
You can choose either format of your choice ( Apa, Mla, Havard, Chicago, or any other)
NB: We do not resell your papers. Upon ordering, we do an original paper exclusively for you.
NB: All your data is kept safe from the public.
My code wont print results then im trying to print the tallest player name and a
My code wont print results then im trying to print the tallest player name and age with their height and inchest
my code:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Project1 {
private static Player tallestPlayer;
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
List players = new ArrayList<>();
System.out.println(“Enter the number of players:”);
int numPlayers = scanner.nextInt();
for (int i = 0; i < numPlayers; i++) {
System.out.println("Enter player " + (i+1) + " information:");
System.out.print("Name:");
String name = scanner.next();
System.out.print("Height (feet):");
int feet = scanner.nextInt();
System.out.print("Height (inches):");
int inches = scanner.nextInt();
System.out.print("age:");
int age = scanner.nextInt();
players.add(new Player(name, new Height(feet, inches), age));
}
double totalAge = 0;
for (Player player : players) {
totalAge += player.getAge();
}
double averageAge = totalAge / players.size();
System.out.println("Average age: " + averageAge);
Player tallestPlayer = players.get(0);
for (int i = 1; i < players.size(); i++) {
Player player = players.get(i);
int totalFeet = player.getHeight().getFeets();
int totalInches = player.getHeight().toInches();
if (totalFeet > tallestPlayer.getHeight().getFeets() || (totalFeet == tallestPlayer.getHeight().getFeets() && totalInches > tallestPlayer.getHeight().toInches())) {
tallestPlayer = player;
}
}
}
System.out.println(“tallest player: ” + tallestPlayer.getName());
}
}
class Height {
private int feet;
private int inches;
public Height(int feet, int inches) {
this.feet = feet;
this.inches = inches;
}
public int toInches() {
return feet * 12 + inches;
}
public int getFeets() {
return feet;
}
@Override
public String toString() {
return feet + “‘:'” + inches;
}
}
class Player {
private String name;
private Height height;
private int age;
public Player(String 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 + “, Hectaight: ” + height.toString() + “, Age: ” + age;
}
}
Do you need this or any other assignment done for you from scratch?
We have qualified writers to help you.
We assure you a quality paper that is 100% free from plagiarism and AI.
You can choose either format of your choice ( Apa, Mla, Havard, Chicago, or any other)
NB: We do not resell your papers. Upon ordering, we do an original paper exclusively for you.
NB: All your data is kept safe from the public.
Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount