Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 1 ( 1 5 pts ) For the IntArrayBag class discussed in class ( you can use IntArrayBag.java from the textbook ) , implement
Question pts
For the IntArrayBag class discussed in class you can use IntArrayBag.java from the textbook implement
a new method called equals with a boolean return value and one parameter. The parameter, called is
another IntArrayBag. The method returns true if and the bag that activates the method have exactly
the same number of every element. Otherwise, the method returns false. Notice that the locations of the
elements in the data arrays are not necessarily the same. It is only the number of occurrences of each
element that must be the same.
For example, for the two bags and they are equal because they have the
same number of every element: one two and one
Question pts
In this question, you will design a data structure that can be used to store some locations in a three
dimensional space.
We will implement the Location DSet class to store a set of locations. The LocationDSet class should
implement the functionality of a collection whose space can grow automatically when adding more locations.
The class LocationDSet should define proper instance variables and implement the following methods.
pts This class should include proper instance variables to keep all location objects and the actual
number of locations.
pts A noargument constructor, which initializes a Location DSet instance, sets its capacity to
and creates an array to store LocationD objects.
public LocationDSet
pts The following method which returns the actual number of elements in this collection.
public int size
pts The following method which returns the capacity of this collection instance.
public int capacity
pts A method which adds one given Location D object to the first available space of the
LocationD array in this LocationDSet instance. When the collection space is sufficient to hold
the new location, this location object can be directly added to the collection. Otherwise, you need to
double the space of the instance array by implementing a method ensureCapacity defined
below The precondition is that the location object a should NOT be null.
public void addLocationD a
pts A method to remove from the collection the location with the given
public boolean remove double double double z
pts The following method guarantees the capacity of the collection. If this collection's capacity is
smaller than the input parameter, this method sets the capacity to minimumCapacity and enlarges
the array to hold minimumCapacity objects; otherwise, this collection is left unchanged. The
precondition is that the input parameter minimumCapacity should be positive.
private void ensureCapacityint minimumCapacity
pts A method which checks whether the collection contains a location with the given
public boolean contains double double y double z
pts A method to save of all locations in the set to a csv file. The content format of the
csv file should be:
pts Write a method to calculate the nearest neighbors of each location and store those in the
location's nearest neighbor array. We will use Euclidean distance to calculate the distances between
points.
public void findnearestneighbors
The Euclidean distance between a point and a point is computed as
follows:
pts main method to thoroughly test your code.
Design test cases, put them in your main method, run your program through the test cases. One test
case need to read all the location information from the data file samplecsv on Canvas and add
those locations to a location set. You should not use an array with fixed size to keep the location
information. You cannot use any Java builtin collections eg ArrayList either.
public static void mainString args
pts Properly run javadoc command to generate java documents for your class.
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