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

  Write a for loop that adds the integers

Assume the int variables i , lo , hi , and result have been declared and that lo and hi have been initialized. Write a for loop that adds the integers between lo and hi (inclusive), and stores the result in result .

  Write function to count the number of sentences

Count the number of words as well as the sentences and return and average the number of words per sentence.

  What is the size of the hash table

What is the size of the hash table?What are hFint256() (16) and hFint256() (257)?

  Program that opens a file representing an encoded maze

Write a C++ program that opens a file representing an encoded maze and reads it in properly so it can be analyzed.

  The program will read integers values

Write a C++ program to do the following. The program will read integers values one at a time from standard input (cin) until you read the value 150. assume that the number of values read in is at least 1 and less than or equal to 100

  Formulate an linear programming model

1. Formulate an Linear Programming model for this problem 2. Create a spreadsheet model for this problem and solve it using Solver 3. What is the optimal solution?

  Write a gui application that prints out hello

Write a GUI application that prints out "Hello!" in either: English, French, or Spanish. When the user selects another language, the greeting shown in the greeting area should change. Your GUI should look like the interface shown below

  Calculate and output the average grade

Program should still ask the user to input a grade integer from 1-100 and then output the letter grade -  your application will calculate and output the average grade for students input.

  Database configuration tools wizard

If your designed solution involves the use of a disconnected database, post the changes back to the live database. Be sure to check the database records to make sure the changes have been made. For an added challenge, write program statements, as ..

  Determine an appropriate functional decomposition

Create structure charts for a problem and determine an appropriate functional decomposition or top-down design from a structure chart

  T computes and posters the probabilities of two people

Write a C program that computes and posters the probabilities of two people in a group who are born in the same day. The probability of two people being born in the same day of the year, for a group of  n people, is given by the following formula:

  C++ class that has a dynamic array of a string

show  an example of a C++ Class that has a dynamic array of a string that takes in names by user input??

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