Computes the measure of an object.

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

Using a different Measurer object, process a set of Rectangle objects to find the rectangle with the largest perimeter.

You need to supply the following class in your solution:
PerimeterMeasurer

Use the following class as your tester class:
import java.awt.Rectangle;

/**
This program tests the measurement of rectangles by perimeter.
*/
public class PerimeterTester
{
public static void main(String[] args)
{
DataSet data = . . .;

data.add(new Rectangle(5, 10, 20, 30));
data.add(new Rectangle(10, 20, 30, 40));
data.add(new Rectangle(20, 30, 5, 10));

double avg = . . .;
Rectangle max = . . .;

System.out.println("Average perimeter: " + avg);
System.out.println("Expected: ");
System.out.println("Largest perimeter: " + max);
System.out.println("Expected: ");
}
}

/**
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;
}
}

/**
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);
}

Reference no: EM13939841

Questions Cloud

Cost accounting systems used by manufacturing : Cost accounting systems used by manufacturing companies are based on the: Periodic inventory system.
Issued dividend of per share on its common stock : The Muse Co. just issued a dividend of $3.45 per share on its common stock. The company is expected to maintain a constant 7.10 percent growth rate in its dividends indefinitely. If the stock sells for $69 a share, what is the company’s cost of equit..
Discuss your reaction to the public service announcement : Discuss your reaction to the public service announcement in relation to the marketing of junk food to children, with a focus on why or why not this PSA is appropriate.
Implications relative to religious freedom of employers : Does the Hobby Lobby decision have other implications relative to religious freedom of employers? If so, what might they be?
Computes the measure of an object. : This program tests the measurement of rectangles by perimeter.
What is the expected return on your portfolio : You analyze the prospects of several companies and come to the following conclusions about the expected return on each: You decide to invest $4,000 in star bucks, $6,000 in Sears, $12,000 in Microsoft, and $3,000 in Limited Brands. What is the expect..
Point estimate of the proportion of selling company : Provide a point estimate of the proportion of selling company's stock which is obsolete. To give a measure of the uncertainty in this estimate, construct a 90% confidence interval for the true proportion of stock which is obsolete.
What measures company must take to capture any reductions : Calculate the nonvalue-added usage and costs for materials usage and sustaining engineering. In particular, discuss what measures the company must take to capture any realized reductions in resource usage.
Recommend options that would be consistent with organization : Recommend options that would be consistent with the organization's accounting practices, accounting processes, and accounting-relateddepartments.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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