Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write a Java class called FlexArray that has/does the following Has a private variable array that holds integers as int[] array. Has a private

image text in transcribed
1. Write a Java class called FlexArray that has/does the following Has a private variable array that holds integers as int[] array. Has a private variable capacity that is the maximum number of integers the array can hold. Has a private variable size that shows the number of currently occupied locations. Obviously, copacity > Sire. Capacity tells you how many values the array can hold, not how many it has currently, which is available via the variable size Has a default constructor that sets capacity=10 and allocates array to new int[copacity Then sets size because there is currently no value stored in the array yet. Has a non-default constructor having parameter (int maxEntries) that sets up array to hold maxEntries number of integers, sets capacity maxEntries and size=0. Make sure maxEntries is >0 This array has the property that only consecutive entries starting from location can contain integer values. In other words, the array contains values in locations through size-1, which is equal to a total of size number of values. A method called public void add/intval) adds the integer val at location size of the array as long as size capacity. If size is equal to capacity, there should be an error message saying, Array is full, values cannot be added. add..) method when successful will also increase the size by 1. A method called public int set fint vol int location) that sets the value at location of array to val, returning the old value to the caller (the old value is replaced with the new value val). The method should throw an error, if location size or location , meaning that you can only modify existing values in the array to new values. A method called public int getint location) that returns the value stored at location of the array. The method should throw an error if location size or location

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions