Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are two data field; - an array of integer values called data and an intege

ID: 440239 • Letter: T

Question

There are two data field; - an array of integer values called data and an integer called manyItems. manyItems keeps track of how many values m the array are valid data. There are two constructors. One that takes no arguments - initialize the data array with size 10 and set manyItems to 0 (there are no items in the array at the time of construction. The second constructor takes a single integer argument which is the initial size of the array (i.e.. may be something other than 10). Again the initial value for manyItems should be 0. There should be an add method - this is where the magic happens The add method takes a single argument, an integer to be added to the array. If there is no room in the array (i.e., manyItems = the size of the array) then do nothing. When you add the integer to the array you must add it in the correct location so that the array is always sorted (from smallest to largest). This means finding the proper location where the value should go and. if necessary, moving all of the other values down to make space. Be careful here or you will overwrite some of your values. -You know how to do this already from assignment 1! After a new element is added manyItems is increased to indicate that the array has a new item in it. There should be a to String () method that prints the valid values of the sequence - make use of manyItems here There should also be an is Found () method that takes a single integer number as an argument and returns true if the number is found in the sequence There is no way to remove items from your sequence ***Write JavaDoc comments for this class.*** Write a tester class that tests your SortedSequence. Prompt the user to enter an initial size for the sequence. Create the SortedSequence object and prompt the user to enter the appropriate number of values which you add to your object using the add method. Display the sequence after each add to ensure that the sort is working. After the sequence is fully populated test your isFound() method by prompting the use to enter a couple of numbers to search for. Hints: Remember, when you first create your array. you'll have a bunch of 0's in it - these should not be considered valid data, manyItems is used to keep track of how many values are actually correct. All of your methods should make use of manyItems when going through the array. Data in positions beyond manyItems are invalid and should not be considered DO NOT use any array sorting methods - you must do the sorting yourself in add() as described above. I used for loops and nextInt() in my loops to avoid prompting the user each time but if it is easier to prompt for each element you can do that. Also, my sequence is printed using the toString() method. How many elements in your SortedSequence?: 8 Here is your sequence so far:Sequence[] Adding 6 items to the list... 9 -1 2 13 1 4 Here is your sequence so far:Secuence[9] Here is your sequence so far:Sequence[-1,9] Here is your sequence so far:Sequence[-1,2, 9] Here is your sequence so far:Sequence[-1,2, 9, 13] Here is your sequence so far:Sequence[-1, 1, 2, 5, 13] Here is your sequence so far:Sequence[-1,1, 2, 4, 5, 13] Enter 2 numbers to search for in the sequence... 12 4 Sorry. 12 could not be found. 4 is present in the sequence! Add a remove() method that takes a single argument, an integer to remove from your array. Your method checks to see if the number is in the array (isFound() anyone?). If it is not found do nothing. If it is found remove it from the array and keep the array sorted. This is VERY similar to your add method. Not showing the output here - you can figure it out!

Explanation / Answer

here is a better program to sort 10 numbers and sort them import java.io.*; public class descendingorder { public static void main(String args[]) throws IOException { BufferedReader in= new BufferedReader(new InputStreamReader(System.in)); int i,j,n,t; int a[]=new int[20]; System.out.println("Enter the number of elements:"); n=Integer.parseInt(in.readLine()); System.out.println("Enter the elements of the array:"); for(i=0;i