Topics Arrays ClassesCoding Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). Keep identifiers to a reasonably short length. User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case withuppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes,methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces ortabs that you use to indent. Use white space to make your program more readable.Part #1 ProgrammingYour assignment is to create a class called NumberCollection in a file called NumberCollection.java (thereis no main method in this class). The NumberCollection class will act as a resizable array of unique integersand provide methods to act on the collection. Therefore the NumberCollection class needs the followinginstance variables: numberArray an array of integers to hold the collection. count an int to hold how many integers have been stored in the array so far.Note: The instance variable count will usually be different than the capacity of the array (numberArray.length).In order to provide access to the collection, the class NumberCollection must include the following constructorand methods. (If your class does not contain any of the following methods, points will be deducted.) public NumberCollection(int arraySize) It constructs an empty NumberCollection object withan array capacity specified by the integer parameter arraySize. That is, it stores a new int array withsize arraySize in the numberArray instance variable. private int indexOf(int searchingNum) It returns the index of the number specified by theparameter is located. If the number is not found, it returns -1. This is a helper method. public boolean addNumber(int numberToAdd) The method will add numberToAdd at the smallestavailable index in the array, if the number is not in already in the array. Be sure to check if the numberis already in the array: Hint: This can be done using the indexOf method to see if it returns -1 or not.1 If the number is in the array, then it will not be added again and the method returns false toindicate that nothing was added. If the number is NOT in the array, continue.If the number is not in the array, be sure to check if the array has reached its capacity. Hint: What is the relationship between the instance variable count and the length of numberArrayif the capacity is reached. If the capacity is reached, double the length of numberArray. Hint: You can use the Arrays.copyOf() method for this as described in Section 6.3.9 of the book. After updating the capacity, if necessary, continue.If the number is not in the array and after updating the capacity, if necessary, then add numberToAddto numberArray at the smallest available index. Hint: Whats the smallest available indexs relationship to count? Hint: Be sure to increase count after adding a new element.If the number is added successfully, then the method returns true. public int findMax() It finds the maximum number among the numbers stored so far (at the timewhen this method is called), and returns it. If the array is empty, return 0. public int findMin() It finds the minimum number among the numbers stored so far (at the timewhen this method is called), and returns it. If the array is empty, return 0. public int computeSum() It computes and returns the sum of numbers stored in numberArray sofar (at the time when this method is called.) If the array is empty, return 0. public String toString() Returns a String containing a list of numbers stored in numberArray.An example of such string can be:{3, 6, -1, 3, 23, -50, 43}The string should start with a { and end with a }.Note: Arrays.toString(numberArray) cannot be used since will not use the required delimiters.That is, you have to write your own loop.Hint: An example of most of these methods can be found in the subsections of Section 6.3 in the bookbeginning on page 258.Helpful Hints Work on it in steps write one method, test it with a test driver and make sure it works before goingon to the next method. Always make sure your code compiles before you add another method. Your methods should be able to be called in any order.Save the NumberCollection class in a file called NumberCollection.java and use the following programstored in Assignment6.java, which has the main method to create new NumberCollection objects and totest your class. You do NOT need to modify Assignment6.java.The program will ask a user to enter a size for the array. Then it will show the following menu to auser:2Command Optionsa: add an integer in the arrayb: display the arrayc: compute and display the maximumd: compute and display the minimume: compute and display the sum?: display the menu againq: quit this programSample Outputs(user input is in bold)Please enter a size for the array.3Command Optionsa: add an integer in the arrayb: display the arrayc: compute and display the maximumd: compute and display the minimume: compute and display the sum?: display the menu againPlease enter a command or type ?b{}Please enter a command or type ?cThe maximum is: 0Please enter a command or type ?dThe minimum is: 0Please enter a command or type ?eThe sum is: 0Please enter a command or type ?aPlease enter an integer to add.55 successfully added.3Please enter a command or type ?aPlease enter an integer to add.1212 successfully added.Please enter a command or type ?aPlease enter an integer to add.-2-2 successfully added.Please enter a command or type ?aPlease enter an integer to add.4141 successfully added.Please enter a command or type ?aPlease enter an integer to add.99 successfully added.Please enter a command or type ?aPlease enter an integer to add.-21-21 successfully added.Please enter a command or type ?b{5, 12, -2, 41, 9, -21}Please enter a command or type ?cThe maximum is: 41Please enter a command or type ?d4The minimum is: -21Please enter a command or type ?eThe sum is: 44Please enter a command or type ?aPlease enter an integer to add.4141 is already in the array. 41 was not added.Please enter a command or type ?b{5, 12, -2, 41, 9, -21}Please enter a command or type ??Command Optionsa: add an integer in the arrayb: display the arrayc: compute and display the maximumd: compute and display the minimume: compute and display the sum?: display the menu againq: quit this programPlease enter a command or type ?qSubmission Go to the course web site (my.asu.edu), and then click on the on-line Submission tab. Submit your Assignment6.java and NumberCollection.java file on-line. Make sure to chooseHw6 from drop-down box. Assignment6.java should have the following, in order: In comments, the assignment header. The working Java code requested in Part #1. The NumberCollection.java and Assignment6.java files must compile and run as you submit it.You can confirm this by viewing your submission results.Important Note: You may resubmit as many times as you like until the deadline, but we will only markyour last submission.NO LATE ASSIGNMENTS WILL BE ACCEPTED.5
hw6_new
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.