Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in java 6. (40 points) Write the class UniqueArray which represents an array whose values are unique, namely no item appears twice. The class can
in java
6. (40 points) Write the class UniqueArray which represents an array whose values are unique, namely no item appears twice. The class can store only reference values. Upon construction of the class, the user will pass an array which may contain duplicate values. Your goal would be to generate a separate array with no duplicates. Your implementation should maintain the original ordering of elements. In addition, your class will provide the method numofoccur which outputs the number of occurrences of an element at position i. Finally, your class will support the method get which returns the item at position i. See also the example below. You must use the modifiers abstract, final, private, protected, public, and static appropriately. In order to get full credit on this problem, it is not enough that your code merely works. You may lose points if you do not use appropriate modifiers where they clearly belong. The code below shows a partial implementation of the class UniqueArray: public class UniqueArray { private object[] arr; public UniqueArray (Object[] arr); public Object get (int i); public int numofoccur (int i); For example, consider the following code: public class Test { public static void main(String[] args) { Integer[] iarr = {1,2,2,3,3,3,4,4,4,4}; UniqueArray uarr = new UniqueArray ( iarr ); System.out.println("uarr at 3: " + uarr.get (3) + W with #occur: " + uarr.numofoccur (3)); The contents of uarr are {1,2,3,4} and the output in this case is: uarr at 3: 4 with #occur: 4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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