Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class name: CircleSet I leave this up to you to determine. You are limited to only using arrays for this implementation, no other Java data

class name: CircleSet
I leave this up to you to determine. You are limited to only using arrays for this implementation, no other Java data structures.

+ public CircleSet(File source) throws FileNotFoundException -- initializes a CircleSet object using the data from the specified file. The data in the set should be in the same order as the data from the file. Throw an IllegalStateException if the file has fewer than 2 Circles

+ int getCount() -- returns the number of Circles in this set + double changingBrightness() -- this methods determines the overall change in brightness from one Circle to the next. Initially, overall change is 0. Going through the set looking at consecutive Circles, if there's an increase in brightness, increment the overall change by 1. If there's a decrease in brightness from one Circle to the next, decrement the overall change by 1. Return this overall change. + Circle[] smallLarge() -- returns an array of two Circles: the Circle with the smallest radius (index 0) and the Circle with the largest radius (index 1). If 2 or more Circles meet the same criteria, return the one stored in the set at the lowest index.

+ Circle[] getClosest() -- returns the two Circle objects whose centers are the closest. The Circles may or may not be next to each other in the array. If there are 2 or more pairs of Circles that are the closest, return the first pair found.

+ String toString() -- returns a String that represents the state of this object. The String should contain the toString() for each Circle object, separated by a new line character.

Please help me to write a class for requirement detail. Thanks

/** Represents a 2-dimensional CSC142Point * @author CSC 142 * @version 2006 */ public class CSC142Point { private double x, y; // the coordinates

// two different constructors /** * Create a CSC142Point at (0, 0) */ public CSC142Point() { x = 0; y = 0; } /** * Create a CSC142Point with the given coordinates * @param initialX the x-coordinate * @param initialY the y-coordinate */ public CSC142Point (double initialX, double initialY) { x = initialX; y = initialY; }

// update (mutator) methods // that change the state of a CSC142Point object

/** * Set the x-coordinate of this CSC142Point * @param updateX the new x-coordinate */ public void setX(double updateX) { x = updateX; } /** * Set the y-coordinate of this CSC142Point * @param newY the new y-coordinate */ public void setY(double updateY) { y = updateY; }

/** * Set the x and y coordinates of this CSC142Point * @param newX the new x-coordinate * @param newY the new y-coordinate */ public void setPoint( double newX, double newY){ x = newX; y = newY; } // query (accessor) methods // that somehow report the state of a CSC142Point // without changing it

/** * Get the x-coordinate of this CSC142Point * @return the x-coordinate */ public double getX() { return x; } /** * Get the y-coordinate of this CSC142Point * @return the y-coordinate */ public double getY() { return y; }

/** * Calculate the distance between this CSC142Point and the origin * @return the distance to (0, 0) */ public double distanceToOrigin() { return Math.sqrt(x * x + y * y); } /** Calculate the distance between this CSC142Point and some other CSC142Point * @param other the other CSC142Point * @return the distance between the 2 CSC142Points */ public double distance(CSC142Point other) { double diffX = x - other.x; double diffY = y - other.y; return Math.sqrt(diffX * diffX + diffY * diffY); } /** * Find the midpoint between this CSC142Point and another CSC142Point * @param p the other CSC142Point * @return the CSC142Point midway between the two CSC142Points */ public CSC142Point midPoint(CSC142Point other) { double midX = (x + other.x) / 2; double midY = (y + other.y) / 2; return new CSC142Point(midX, midY); } /** * The String version of this CSC142Point * @return the String representation */ public String toString() { return "(" + x + ", " + y + ")"; } /** * a test method - do not change this code! * it should display 3 results in a terminal window */ public static void test (){ CSC142Point alpha = new CSC142Point( 5, 5 ); CSC142Point beta = new CSC142Point( -3, 7 ); System.out.println( "alpha is " + alpha.distanceToOrigin() + " from the origin" ); System.out.println( "The x coordinate of beta is " + beta.getX() ); beta.setY( 72 ); System.out.println( "The y coordinate of beta is " + beta.getY() ); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Classify delivery styles by type.

Answered: 1 week ago