Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help please, I would like to understand this program by looking how the program would look like. Class Numbers Instance Variables: ? a

I need help please, I would like to understand this program by looking how the program would look like.

Class Numbers

Instance Variables:

? a dynamically allocated array of Integer (using wrapper class here)

? an int to hold the size of the array

Methods

? No-arg constructor

? Parameterized (initial) constructor that accepts an int parameter that sets the size of the array

? Method generateNumbers that uses the Random class to fill the array with random numbers between 1 and 50.

? Method findCount that will return an int which is the number of occurrences of a number in the array

? Method findIndex that returns an int which is the index of the number if it is present in the array. Returns -1 otherwise.

? Method toString returns a String of the values in the array (you are asked to override the existing toString method)

? Method isArrayCreated that returns -1 if array is not created with a given size. Returns 0 otherwise.

? Method isEmpty that returns -1 if the array is not created with an integer size greater than 0. Returns 0 otherwise.

? Method sortNumbers that sorts the numbers in the array. In this lab, you can use Arrays.sort() for sorting.

? Method iterativeBinarySearch that returns the index of the key if it is present in the array. Returns -1 otherwise.

? Method recursiveBinarySearch that returns the index of the key if it is present in the array. Returns -1 otherwise.

Class Lab 1

Methods

? main - creates an object of Numbers and displays a menu that prompts users to execute each of the methods above and prompts for user input (See output below). You can use System.err.println() to print the output in error. If you are experiencing order issues in output (error message prints after showing the menu), you can use System.err.flush() to flush out the stream. You need to thoroughly check the expected output to see the flow.

ps. When it prints the array, it has print index and element, e.g.

image text in transcribed
\f

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions