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

  Create a boolean function that computes

Create a Boolean function that computes the value of a factorial for values up to including 10. Include comments about how to use the function and describing how it works.

  Program that stores information for date-time objects

Derive class WeekDay from class DateTime such that WeekDay::display() will display local date time using values from the parameters and the corresponding weekday.

  A sample of helium gas occupies 945ml at 605 mmhg

A sample of helium gas occupies 945mL at 605 mmHg. For a gas sample at a constant temperature, determine the volume of helium at 745 mmHg?

  Write a program in c that arranges and prints out

When playing poker and other card games (standard 52 cards, excluding the jokers), it is usual to arrange a hand to reflect its values. Write a program in C that arranges and prints out a random hand of ten cards in sorted order by pips values.

  The relative strengths of acids and bases table

List, in a general way, the information that is provided in the Relative Strengths of Acids and Bases table. Explain how the information in the Relative Strengths of Acids and Bases table is used to support your work in this unit. Use examples to su..

  Find and print the largest number in the array

Write a C program that declares an (integer) array of size 10, prompts the user to enter 10 integers and stores them in the array. The program should then

  32 times a plus b write as a c++ expression

The string that represents the name Julie Nelson

  Scenario 1: a thief enters your dwelling

Scenario 1: a thief enters your dwelling and steals your computer.is it possible likely that he steals your backup device with backup copies? how do you recover from such an incident?

  Given a character code to indicate the type of customer

Pete's Plumbing of Pompey sells to both retail and wholesale buyers. The retail buyer must pay New York State and Onondaga County sales tax (8%). However, the wholesale buyer does not pay sales tax and receives a volume discount on the amount purchas..

  Write a program that uses a string array to store a list

The program should allow the user via a menu to add an item to the list, clear the list, and display the list. You may assume that the list will never need to contain more than 10 items.

  Roman numeral equivalents of the decimal numbers

Write a program that prints a table of all the Roman numeral equivalents of the decimal numbers in the range 1 - 100.

  Writing out the results to the console

This assignment consists of reading three files and writing out the results to the console. The three files can be found on Moodle: text.bin, bin_data.bin, and mixed.bin

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