Question: Can I get 5 testplan examples, and UML Class diagram for my following code java code? import java.util.ArrayList; import java.util.Scanner; class Height { private final

Can I get 5 testplan examples, and UML Class diagram for my following code java code? import java.util.ArrayList;
import java.util.Scanner;
class Height {
private final int feet;
private final int inches;
public Height(int feet, int inches){
this.feet = feet;
this.inches = inches;
}
public int toInches(){
return feet *12+ inches;
}
@Override
public String toString(){
int normalizedInches = inches %12;
return feet +"'"+ normalizedInches +"\"";
}
}
class Player {
private final String name;
private final Height height;
private final 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 +", Height: "+ height.toString()+", Age: "+ age;
}
}
public class Project1{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
ArrayList players = new ArrayList<>();
int totalAge =0;
System.out.print("Enter the number of players: ");
int numPlayers = scanner.nextInt();
scanner.nextLine(); // Consume the newline
for (int i =0; i < numPlayers; i++){
System.out.print("Enter player's name: ");
String name = scanner.nextLine();
System.out.print("Enter player's height (feet inches): ");
int feet = scanner.nextInt();
int inches = scanner.nextInt();
Height height = new Height(feet, inches);
scanner.nextLine(); // Consume the newline
System.out.print("Enter player's age: ");
int age = scanner.nextInt();
scanner.nextLine(); // Consume the newline
totalAge += age;
Player player = new Player(name, height, age);
players.add(player);
}
double averageAge =(double) totalAge / numPlayers;
System.out.println("Average age of all players: "+ averageAge);
Player tallestPlayerBelowAverage = null;
int maxHeight =0;
for (Player player : players){
if (player.getAge()<= averageAge && player.getHeight().toInches()> maxHeight){
maxHeight = player.getHeight().toInches();
tallestPlayerBelowAverage = player;
}
}
if (tallestPlayerBelowAverage != null){
System.out.println("Tallest player below or equal to average age: "+ tallestPlayerBelowAverage);
} else {
System.out.println("No player found matching the criteria.");
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!