Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using this information: import java.util.ArrayList; import java.util.Scanner; class Height { private final int feet; private final int inches; public Height ( int feet, int inches

Using this information: 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 String.format("%d'%d\"", 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 String.format("Name: %s, Height: %s, Age: %d", name, height.toString(), 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.println("Enter player information (type 'done' to finish):");
while (true){
System.out.print("Name: ");
String name = scanner.nextLine();
if (name.equalsIgnoreCase("done")){
break;
}
System.out.print("Height (feet): ");
int feet = scanner.nextInt();
System.out.print("Height (inches): ");
int inches = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
System.out.print("Age: ");
int age = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
Height height = new Height(feet, inches);
Player player = new Player(name, height, age);
players.add(player);
totalAge += age;
}
if (!players.isEmpty()){
double averageAge =(double) totalAge / players.size();
System.out.println("Average Age of Players: "+ averageAge);
Player tallestPlayer = findTallestPlayer(players, averageAge);
System.out.println("Tallest Player: "+ tallestPlayer.toString());
} else {
System.out.println("No player information entered.");
}
}
private static Player findTallestPlayer(ArrayList players, double averageAge){
Player tallestPlayer = null;
int maxHeight =0;
for (Player player : players){
if (player.getAge()<= averageAge){
int totalHeight = player.getHeight().toInches();
if (totalHeight > maxHeight){
maxHeight = totalHeight;
tallestPlayer = player;
}
}
}
return tallestPlayer;
}
} write a. A UML class diagram that includes all classes you wrote. Do not include
predefined classes.
b. A test plan that includes test cases that you have created indicating what aspects
of the program each one is testing
c. A short paragraph on lessons learned from the project

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

ISBN: 0619064625, 978-0619064624

More Books

Students also viewed these Databases questions

Question

Prepare a constructive performance appraisal.

Answered: 1 week ago

Question

List the advantages of correct report formatting.

Answered: 1 week ago