Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help with this program on netbeans bssignment 7: User-Filled Array Buffer This assignment builds on Assignment 5. in Assignment 5, your lotegsrAtay class always used

image text in transcribed

image text in transcribed

help with this program on netbeans

bssignment 7: User-Filled Array Buffer This assignment builds on Assignment 5. in Assignment 5, your lotegsrAtay class always used a completely filled array. But what if you add values only one at a time, and don't know how many items you will have when you are done? in this assignment, you will create an array "buffer" without filling it right away. That means that you have an array but most of the values are meaningless zeroes. At the beginning, all of the values are meaningless zeroes. Only as you begin putting values into the array do some of the elements become meaningful. The important idea to capture, is that the "size" or capacity of the array, and the number of values in the array (or "count"), are two separate numbers. Start a project, as ahways. Create your main class with the same name as the project. Then create a new dass called totesetter The jtecutfer lass will have two private variables: an array of jots (private int buffer[].), and a count of the number of values that have been added, called numberstvaluss, The class should have two constructors. The constructor that takes no arguments should create an array of 100 ts lusing a constant called BUFFER SZ) for initializing the array: buffer new int BUFFER sZ]- The other constructor takes an integer argument and uses that to create the initial buffer array of that size. Both constructors should set the puwberotvalue to o have the following methods The jnteeerBuffer class should add (which scans an integer as input and puts its value in the array OR adds a random integer to the array using the Math randgml)l, The user is asked to choose between the two options. So either the user has to enter a number or a random number is added to the array. ssNumbexatsalues (which is a getter to return the current pumbscotvaluea), and eoiTsCenRS which works like the priotiteral method in assignment 5, except that it only prints as many values as have been added The key to making the addl) method work is that when the array is empty (nothing yet added), it puts the first value in location o, which would be bufferlo]- value, After getting its first value, the oumberatvaiess should be "incremented" so it becomes 1. Then next time addj is called to add a value that value should be put in location 1: buffer[1]- value; and the pumberoivalues is incremented as before, and becomes 2. We cannot write the actual array index in the assignment, because each time alue, that index must be one bigger than the array index we used before. But notice that e add the array index that we want to use is the same value as the puabsuotvalues before the new value is added. In other words, when the pumberoivalusi is 0, the next value goes in location o. when the oumettotuseg is 1, the next value goes in location 1. When the Duneestalsea s 18, the next alue will go in location 18. So the addi) method should use the psobarstcalusa variable as the array index for the new value, and then increment it after the new value has been added to the buffer array: buffer(count] - value call the add method within a while loop which asks "Do you want to add numbers to the array? The loop should end when the value given is "No" (or some other clever mechanism if you want to make this more generaily useful], when you run your pragram, you numbers using add. Your code should then show how many numbers you entered and print lusing the print method) only the numbers that you entered As a last step, make the joteeerBufter more robust should be able to use it to enter a series of

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

Logics For Databases And Information Systems

Authors: Jan Chomicki ,Gunter Saake

1st Edition

1461375827, 978-1461375821

More Books

Students also viewed these Databases questions