Display the average height and name of the tallest person

Assignment Help C/C++ Programming
Reference no: EM13939940

A person has a name and a height in centimeters. Implement a dataset to process a collection of Person objects. Display the average height and the name of the tallest person.

Use the following class in your solution:
/**
This class represents a person's name and height
*/
public class Person
{
private String name;
private double height;

/**
Constructs a Person object
@param aName the name of the person
@param aHeight the height of the person
*/
public Person(String aName, double aHeight)
{
name = aName;
height = aHeight;
}

/**
Gets the name of the person
@return name the person's name
*/
public String getName()
{
return name;
}

/**
Gets the height of the person
@return height the person's height
*/
public double getHeight()
{
return height;
}
}

Use the following class as your tester class:
/**
This program tests the measuring of Person objects.
*/
public class PersonTester
{
public static void main(String[] args)
{
. . .

DataSet data = . . .

data.add(new Person("Joe", 183));
data.add(new Person("Chrissy", 158));
data.add(new Person("Bobby", 175));

double avg = . . .
Person max = . . .

System.out.println("Average height: " + avg);
System.out.println("Expected: 172");
System.out.println("Name of tallest person: " + max.getName());
System.out.println("Expected: Joe");
}
}

DO NOT MODIFY THE FOLLOWING:

/**
Computes the average of a set of data values.
*/
public class DataSet
{
private double sum;
private Object maximum;
private int count;
private Measurer measurer;

/**
Constructs an empty data set with a given measurer.
@param aMeasurer the measurer that is used to measure data values
*/
public DataSet(Measurer aMeasurer)
{
sum = 0;
count = 0;
maximum = null;
measurer = aMeasurer;
}

/**
Adds a data value to the data set.
@param x a data value
*/
public void add(Object x)
{
sum = sum + measurer.measure(x);
if (count == 0
|| measurer.measure(maximum) < measurer.measure(x))
maximum = x;
count++;
}

/**
Gets the average of the added data.
@return the average or 0 if no data has been added
*/
public double getAverage()
{
if (count == 0) return 0;
else return sum / count;
}

/**
Gets the largest of the added data.
@return the maximum or 0 if no data has been added
*/
public Object getMaximum()
{
return maximum;
}
}

DO NOT MODIFY THE FOLLOWING
/**
Describes any class whose objects can measure other objects.
*/
public interface Measurer
{
/**
Computes the measure of an object.
@param anObject the object to be measured
@return the measure
*/
double measure(Object anObject);
}

DO NOT MODIFY THE FOLLOWING
/**
This class represents a person's name and height
*/
public class Person
{
private String name;
private double height;

/**
Constructs a Person object
@param aName the name of the person
@param aHeight the height of the person
*/
public Person(String aName, double aHeight)
{
name = aName;
height = aHeight;
}

/**
Gets the name of the person
@return name the person's name
*/
public String getName()
{
return name;
}

/**
Gets the height of the person
@return height the person's height
*/
public double getHeight()
{
return height;
}

Reference no: EM13939940

Questions Cloud

Compute cost of goods transferred out and the cost of ewip : Prepare a physical flow schedule. Prepare a schedule of equivalent units. Compute the cost per equivalent unit. Compute the cost of goods transferred out and the cost of EWIP.
Facilitate the successful implementation of diversity policy : How can managers facilitate the successful implementation of diversity policy?
Calculate the channel capacity : Calculate the channel capacity and what is the minimum transmission time to required transfer all characters over the channel without error?
What was the attention to details : Ideas and links for obtaining a recent (less than 6 months old) article from the popular press (newspaper or magazine) and a peer reviewed journal article on the same or similar topic are included. Advice on how to clearly summarize each article i..
Display the average height and name of the tallest person : A person has a name and a height in centimeters. Implement a dataset to process a collection of Person objects. Display the average height and the name of the tallest person.
Issue of preferred stock : Holdup Bank has an issue of preferred stock with a $4.95 stated dividend that just sold for $86 per share. What is the bank’s cost of preferred stock?
General funds are blocked by the argentine government : General Eletric's funds are blocked by the Argentine government. GE still wants to continue its operations in the country. Under the circumstance, GE should
Draw the shear force diagram : a) Draw the shear force diagram and indicate the position of maximum bending moment.
Essay - ethical implications of a social psychology study : In this assignment, you will write an essay about the research methods and ethical implications of a social psychology study. You will get information about the study from one of the entries in the SPARQ "Solutions Catalog"

Reviews

Write a Review

C/C++ Programming Questions & Answers

  What value will be printed in the code

In the following code snippet, what value will be printed for c and d before the loop is executed

  Composite data types (arrays & records)

Composite data types (arrays & records) can be a problem when they are passed as parameters or returned by functions. Why?

  Calculate the cost of carrying additional luggage

The application used to calculate the cost of carrying additional luggage results in erroneous amount, if the weight of the luggage is a fractional number. Help the development team modify the code snippet so that the cost of carrying additional lu..

  Write a c program that display the hexadecimal equivalent

Write a C program that will accept a hexadecimal number as input, and then display a menu that will permit any of the following operations to be carried out: (a) Display the hexadecimal equivalent of the one"s complement.

  Identify the primary and secondary variables

Identify the primary and secondary variables and construct the weak form of the nonlinear equation

  Write a function named read_line

supposes you have a directory whose name is stored in 'specs.file_dir' which contains a file whose name is stored in 'specs.file_name'.

  Program to produce ten random permutations of numbers

In C++(must be able to compile in Visual Studio ): Write a program to produce ten random permutations of numbers 1 to 10.

  What is the output of the program below

What is the output when the following code fragment is executed?

  Programming questions

Write a program (including timing measurements) for the following scenario. Generate 20 million random numbers, one at a time, and insert them into an array that doubles every time it runs out of space (starting size of 2), into an array that can..

  Write a program that accepts as input a string variable

Write a program that accepts as input a string variable called strFirstName, then another string variable called strLastName, and an integer variable called intAge.

  Check the program and correct it

Modify the attached program to not just say you won, lost, or tied but to say how, no matter if you win, lose, or tie.

  Draw the extensive-form version of game

Consider a game between Joe and Snake. This game takes place in the morning after Joe has had breakfast. Snake can do two things: fight Joe or not. He likes fighting with people who are feeling cowardly and gets a payoff of 1 if he does. Snake, howev..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd