Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: Programming (13 points Your assignment is to create a class called Numbers in a file called NumberCollection.java. (there is no main method in

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Part 2: Programming (13 points Your assignment is to create a class called Numbers in a file called NumberCollection.java. (there is no main method in this class). A class NumberCollection has an array of integers and a count (integer) as instance variables. The variable count keeps track how many integers are stored in the array. The variable name for the array of integers is numberArray Note: You need to distinguish the array size (capacity) and "count" that keeps track of numbers added to this array so far The class NumberCollection must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted.) Method public NumberCollection int arraySize) private int indexOf int searchingNum) escription of the Method It constructs an empty NumberCollection object with an array capacity specified by the integer arravSize It returns the index of the number specified by the parameter is located. If the number is not found, it returns-1. It is a service (helper) method. method checks if the integer specified by the parameter exists in the array (This can be done sing the indexOf method to see if it returns-1 or not) and also checks if the array has not reached its capacity. If both are satisfied, the number is added to the array at the smallest available index. If array reached its capacity, double its size by calling the method doubleArrayCapacity and add e number. If the number is added successfully, then the method returns true. If the number already public boolean addNumber(int numberToAdd) xists in the array, the new number will not be added, and the method returns false method checks if the integer specified by the parameter exists in the array (This can be done sing the indexOf method to see if it returns-1 or not) and if it does, it removes the number and then ublic boolean remove(int numberToRemove) t shifts all the integers to the left and returns true it returns false It is a service (helper) method and doubles the capacity of the numberArray. Please see the example in page 353, the method increaseSize() as a reference private void doubleArrayCapacityO It finds the range of values in the array. The range is defined as 1 more than the difference between public int findRange(0 max imum and minimum in the It computes and returns the average of numbers stored in the numberArray so far (at the time when Public doublet compute Avg) is method is called.) If the array is empty, return 0 s a String containing a list of numbers stored in the numberArray. An example of such string an public String toString) (3, 6, -1,3,23, -50,43; string should start with a'and end witha

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions