Question: 1. Please complete the following Java class which is an implementation of a buffer of integers. with instructions labelled a and b below the incomplete
1. Please complete the following Java class which is an implementation of a buffer of integers.
with instructions labelled a and b below the incomplete code.
class IntBuff
{
int[] elements; // the content of the buffer
int current_size; // the number of valid elements
IntBuff() // initialize an empty buffer of maximum size 0
{
...
}
// initialize an empty buffer of maximum size n
IntBuff(final int n)
{
...
}
// initialize a buff which is a copy of buff
IntBuff(IntBuff buff)
{
...
}
// append the value v to the buffer
// return true if the operation is successful otherwise false
boolean append(final int v)
{
...
}
// insert the value v to the buffer at the position of index
// return true if the operation is successful otherwise false
boolean insert(final int index, final int v)
{
...
}
// delete the element at the position of index in the buffer
// return true if the operation is successful otherwise false
boolean delete(final int index)
{
...
}
// display all of the (valid) elements in the buffer
void println()
{
...
}
}
Requirements:
a) Please complete the above implementation of the class IntBuff and keep it as a file IntBuff.java.
b) Please write a main method to perform the following steps based on the class IntBuff.
1. Create an integer buffer by appending the values 51, 7, 89, 106, 2, 0, -18 to an empty one.
2. Display the content of the buffer.
3. Delete the element of the index 3.
4. Display the content of the buffer.
5. Insert the value -50 at the position of index 5.
6. Display the content of the buffer.
Step by Step Solution
3.45 Rating (155 Votes )
There are 3 Steps involved in it
IntBuffclass package mypackage class IntBuff int elements the content of the buffer int currentsize ... View full answer
Get step-by-step solutions from verified subject matter experts
