Question
public interface RectangleInterface { /** * Returns the x coordinate of this Rectangle's top-left corner. * @return the x coordinate of this Rectangle's top-left corner
public interface RectangleInterface { /** * Returns the x coordinate of this Rectangle\'s top-left corner. * @return the x coordinate of this Rectangle\'s top-left corner */ public int getX();
/** * Returns the y coordinate of this Rectangle\'s top-left corner. * @return the y coordinate of this Rectangle\'s top-left corner */ int getY(); /** * Returns the width of this Rectangle. * @return the width of this Rectangle. */ int getWidth();
/** * Returns the height of this Rectangle. * @return the height of this Rectangle. */ int getHeight(); /** * Sets the (x, y) coordinate of this Rectangle\'s top-left corner as well * as the width and height of this Rectangle to the given values. * @param x The new x coordinate for this Rectangle\'s top-left corder * @param y The new y coordinate for this Rectangle\'s top-left corder * @param width The new width for this Rectangle * @param height The new height for this rectangle */ public void setRect(int x, int y, int width, int height); /** * Sets the (x, y) coordinate of this Rectangle\'s top-left corner as well * as the width and height of this Rectangle to match the corresponding * values in the given Rectangle. * @param otherRectangle The rectangle who\'s values are to be used for * this rectangle. */ public void setRect(Rectangle otherRectangle); /** * Changes the (x, y) coordinates of this Rectangle\'s top-left corner by * adding the given values. * @param deltaX The amount to move in the x direction * @param deltaY The amount to move in the y direction */ public void translate(int deltaX, int deltaY);
/** * Returns a new Rectangle representing the intersection of this * Rectangle with the specified Rectangle. * @param otherRectangle the Rectangle to be intersected with this Rectangle * @return the largest Rectangle contained in both the specified Rectangle * and in this Rectangle. */ public Rectangle createIntersection(Rectangle otherRectangle); /** * Determines whether or not this Rectangle and the specified Rectangle * intersect. For this assignment, two Rectangles are said to intersect only * if their interiors overlap. * @param otherRectangle The specified Rectangle * @return true if the specified Rectangle and this Rectangle intersect; * false otherwise. */ public boolean intersects(Rectangle otherRectangle); /** * Calculates the area of this Rectangle. * @return the area of this rectangle */ public int area(); /** * Calculates the perimeter of this rectangle. * @return the perimeter of this rectangle */ public int perimeter(); }
public class DataSet { private double sum; private int count; private Object maximum; // Can be any object private Measurer measurer; /** Constructs an empty data set with a given measurer. @param measurer the measurer that is used to measure data values */ public DataSet(Measurer measurer) { sum = 0; count = 0; maximum = null; this.measurer = measurer; } /** Adds a data value to the data set. @param x a data value */ public void add(Object x){ sum += measurer.measure(x); if(count == 0 || measurer.measure(x) > measurer.measure(maximum)){ 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; } }
public interface Measurer { /** * Computes the measurement of an object. * * @param obj the object to be measured * @return the measurement of the given object */ double measure(Object obj); }
Sol52:
The given code includes an interface named \"RectangleInterface\" that provides the basic methods to get and set the attributes of a rectangle shape, including its x and y coordinates, width, and height. It also includes methods to perform basic operations on rectangles, such as changing its position by translation, calculating the area and perimeter, and checking whether two rectangles intersect or not.
Moreover, the code includes a class named \"DataSet\" that constructs an empty data set with a given measurer and provides methods to add data values to the data set, get the average and largest of the added data. The class also includes an interface named \"Measurer\" that provides a method to compute the measurement of an object.
Overall, the code is a combination of basic geometric operations and a data set class that utilizes the concept of measurers to perform computations on data values. It provides a useful framework for performing various computations related to rectangles and data values.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started