Answered step by step
Verified Expert Solution
Link Copied!

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 1(15 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 b, is
another IntArrayBag. The method returns true if b 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 a={1,2,2,3} and b={2,3,1,2}, they are equal because they have the
same number of every element: one 1, two 2s, and one 3.
Question 2(85 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 3DSet class to store a set of locations. The Location3DSet class should
implement the functionality of a collection whose space can grow automatically when adding more locations.
The class Location3DSet should define proper instance variables and implement the following methods.
(5 pts) This class should include proper instance variables to keep all location objects and the actual
number of locations.
(5 pts) A no-argument constructor, which initializes a Location 3 DSet instance, sets its capacity to
10, and creates an array to store 10 Location3D objects.
public Location3DSet()
(5 pts) The following method which returns the actual number of elements in this collection.
public int size()
(5 pts) The following method which returns the capacity of this collection instance.
public int capacity()
(5 pts) A method which adds one given Location 3D object to the first available space of the
Location3D array in this Location3DSet 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 add(Location3D a)
(5 pts) A method to remove from the collection the location with the given x,y,z.
public boolean remove (double x, double y, double z)
(5 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 ensureCapacity(int minimumCapacity)
(5 pts) A method which checks whether the collection contains a location with the given x,y,z.
public boolean contains (double x, double y, double z)
(10 pts) A method to save x,y,z of all locations in the set to a .csv file. The content format of the
.csv file should be:
x,y,z
1.0,1.5,3.0
2.0,4.0,5.0
2.5,3.5,2.1
(15 pts) Write a method to calculate the 3 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 find_nearest_neighbors()
The Euclidean distance between a point A(xA,yA,zA) and a point B(xB,yB,zB) is computed as
follows:
d(A,B)=(xA-xB)2+(yA-yB)2+(zA-zB)22
(10 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 (sample.csv 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 built-in collections (e.g., ArrayList) either.
public static void main(String[] args)
(10 pts) Properly run javadoc command to generate java documents for your class.
image text in transcribed

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

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions

Question

Describe the five elements of the listening process.

Answered: 1 week ago