Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a provided array, determine how many groups of a specified size exist. For the array [1,1,1,2,2,2,3,3,3,4,5,6,7] , there are 7 groups with at least

Given a provided array, determine how many groups of a specified size exist.

For the array [1,1,1,2,2,2,3,3,3,4,5,6,7] , there are 7 groups with at least one, 3 groups with at least 2, and 3 groups with at least 3. A group is a series of same values. 1 1 1 is a group of 3, but it also is a group of 1 and 2. To count as a group, all values must be the same. 1 1 1 is a group of 3 because there are 3 1s in a row.

starter code

public class ArrayStats { // Array to be used when computing Stats int [] array;

/** * Constructor to create an instance of the ArrayStats class * * @param array Array of integers from which the stats will be created */ public ArrayStats(int [] array) { // Add your code here }

/** * Constructor to create an instance of the ArrayStats class * * @param list String of blank seperated integers from which the array stats * will be created. For example, the string might be * "1 2 3 4 5 6 7 8 9". */ public ArrayStats(String arrayAsString) { // Add your code here }

/** * Set array from which the array stats are to be computed * * @param array Array from which stats are to be computed. */ public void setArray(int [] array) { // Add your code here }

/** * Set array from which the array stats are to be computed * * @param arrayAsString Array from which stats are to be computed as * a blank delimited string. For example, the string might be * "1 2 3 4 5 6 7 8 9". */ public void setArray(String arrayAsString) { // Add your code here }

/** * Determine how many groups of at least the specified size exist within the array. * For the array [1,1,1,2,2,2,3,3,3,4,5,6,7], there are 7 * groups with at least one, 3 groups with at least 2, and 3 groups * with at least 3. A group is a series of same values. * 1 1 1 is a group of 3, but it also is a group of 1 and 2. * To count as a group, all values must be the same. 1 1 1 * is a group of 3 because there are 3 1s in a row. * * @param size The number of groups of at least size will be counted. * @return The number of groups of at least size. */ public int getNumGroupsOfSize(int size) { return 0; // Replace the code in this method with your solution }

/** * Return a String representation of the array. * * @return String represenaton of the array. */ public String toString() { // This method has been written for you and is complete // Notice how array is converted to a String. // This is not part of the AP Java subset, but is useful. String retVal=""+Arrays.toString(array); return retVal; } }

Sample Data :

3 3 3 3 3 9 4 4 4 5 5 5 5 6 6 7 7 7 8 8 8 8 8 8 8 8

1 2 3 4 5 6 7 8 9

1 1 1 2 1 1 3 3 3 3 3 3 3 3 3 3 4 4 4 5 4 4 4 6

Sample Output :

[3, 3, 3, 3, 3, 9, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8]

size 1 count == 7

size 2 count == 6

size 3 count == 5

size 4 count == 3

size 5 count == 2

size 6 count == 1

[1, 2, 3, 4, 5, 6, 7, 8, 9]

size 1 count == 9

size 2 count == 0

size 3 count == 0

size 4 count == 0

[1, 1, 1, 2, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 4, 4, 4, 6]

size 1 count == 8

size 2 count == 5

size 6 count == 1

size 8 count == 1

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago