# Boolean Array and sorting elements within it

• May 24th, 2014, 11:18 AM
ohGOSHTash
Boolean Array and sorting elements within it
If I have a boolean array that contains 30 elements (boolean[] fish), how do I go about isolating every 10 elements to use for something specific?

Say there are 30 types of fish stored within the boolean array and 0-9 are fish found specifically in the Indian Ocean, 10-19 are fish found specifically in the Atlantic, and 20-29 are fish specifically found in the Pacific Ocean. And for those 10 fish [0-9], [10-19], [20-29], each is a different color (red, orange, green, blue, white, black, silver, yellow, purple and gold), where the colors and locations of the fish are enum types Colors and Locations.

How do I go about appointing those characteristics to the fish?

Ex: elements [0-9] are fish from the Indian Ocean and [0] is red, [1] is orange, [2] is green, [3] is blue, [4] is white, [5] is black, [6] is silver, [7] is yellow, [8] is purple, and [9] is gold.

elements [10-19] are fish from the Atlantic Ocean and [10] is red, [11] is orange, [12] is green, [13] is blue, [14] is white, [15] is black, [16] is silver, [17] is yellow, [18] is purple, and [19] is gold.

elements [20-29] are fish from the Indian Ocean and [20] is red, [21] is orange, [22] is green, [23] is blue, [24] is white, [25] is black, [26] is silver, [27] is yellow, [28] is purple, and [29] is gold.

Will I need to appoint those characteristics in the constructor after initializing fish = new boolean[30]?
• May 24th, 2014, 11:43 AM
Norm
Re: Boolean Array and sorting elements within it
Quote:

30 types of fish stored within the boolean array
A boolean variable can only have two values: true or false. It can't store types of fish.

Please explain why you are trying to use boolean.
Would another data type be better?
• May 24th, 2014, 12:18 PM
ohGOSHTash
Re: Boolean Array and sorting elements within it
It's a given in the assignment. We have to use the boolean array. I'm aware it only stores True or False. What my professor wants us to do with that is use the boolean array to return True if the element we are searching for is in the array, and return False if it is not.

--- Update ---

So based on what you're saying, I should create another array that is of a String type to store the fish in. But when it comes to searching to see if an element is in the array, how will I implement the boolean array? I'll be working with two different types of arrays.
• May 24th, 2014, 12:19 PM
Norm
Re: Boolean Array and sorting elements within it
Quote:

return True if the element we are searching for is in the array
Not sure I understand.
What is the element that is being searched for
and what is in the array being searched?

Is there another array besides the boolean array?
• May 24th, 2014, 12:33 PM
ohGOSHTash
Re: Boolean Array and sorting elements within it
That's what I'm now confused about. Is there no way to store the different types of fish in the boolean array?

We're searching for certain types of fish. For example, I need to search the array to see if a red fish from the Atlantic Ocean is part of the array. If it isn't, it would return False. The array is supposed to store all of the different types of fish.

--- Update ---

He only gave one array (the boolean array) to work with, but now I'm wondering if I need to go on and create a second array that stores the fish. But if I create the second one, what will be the use of the boolean array and how will I use it in conjunction with the second one I create?
• May 24th, 2014, 12:37 PM
Norm
Re: Boolean Array and sorting elements within it
Quote:

Is there no way to store the different types of fish in the boolean array
Yes there is no way. As I said before, boolean variables only hold two values.

Quote:

The array is supposed to store all of the different types of fish.
You need to define an array that holds "types of fish".

I don't know how you are to use the boolean array.
One possibility: If there were a list of questions that would be answered by true or false, a boolean array could hold the answers to those questions.The answer to the first question at [0], the second at [1], etc
• May 26th, 2014, 12:22 PM
Norm
Re: Boolean Array and sorting elements within it