6 Replies - 353 Views - Last Post: 26 May 2014 - 09:22 AM Rate Topic: -----

#1 Tash.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-July 11

Boolean array and sorting the elements within it

Posted 24 May 2014 - 08:24 AM

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]?

Is This A Good Question/Topic? 0
  • +

Replies To: Boolean array and sorting the elements within it

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5832
  • View blog
  • Posts: 12,684
  • Joined: 16-October 07

Re: Boolean array and sorting the elements within it

Posted 24 May 2014 - 09:23 AM

Sorry, this doesn't make much sense. A boolean array is simply an array of boolean values. The values are true or false. Period.

Now, if each position is a flag of some sort, like 2 is Green Indian Ocean fish, then you could use your boolean array to store characteristics of one fish. Though, if it's Green in one ocean, do you expect it to be red in another? That sounds like a different fish.

You would reasonably want a Fish class in Java with the elements that make sense:
class Fish {
    public String getName() { /* your code here */ }
    public Color getColor() { /* your code here */ }
    public Ocean getOcean() { /* your code here */ }
    public Fish(String name, Color color, Ocean ocean) {
// your code here
}

Fish [] fishes = new Fish[30]; // now you can store 30 different kinds of fish



Hope this helps.
Was This Post Helpful? 1
  • +
  • -

#3 Tash.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-July 11

Re: Boolean array and sorting the elements within it

Posted 24 May 2014 - 09:41 AM

Thank you very much for responding. My professor wants us to use the boolean array to search for an element, and if the element is in the array, it will return True. If not, it will return False. If I end up creating a second array that contains the fish elements, how will I make use of the boolean array? The boolean array becomes pointless, do it not?
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5832
  • View blog
  • Posts: 12,684
  • Joined: 16-October 07

Re: Boolean array and sorting the elements within it

Posted 24 May 2014 - 10:36 AM

Yes, a boolean array seems pointless. Having a search function that looks through an array and returns boolean ( just a single boolean value, not an array) does make sense.

Ask your professor to clarify how a boolean array should be used because it sounds, um, fishy as this point.
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,447
  • Joined: 20-September 08

Re: Boolean array and sorting the elements within it

Posted 24 May 2014 - 11:37 AM

Sounds like you want two EnumSet of colour and location in Fish. You can use Fish.equals with iteration to test for a given one's presence in an array or use a Collection
Was This Post Helpful? 0
  • +
  • -

#6 program94  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 19-April 14

Re: Boolean array and sorting the elements within it

Posted 26 May 2014 - 08:04 AM

What kind of search are you suppose to use?
Was This Post Helpful? 0
  • +
  • -

#7 NormR  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 54
  • Joined: 25-December 13

Re: Boolean array and sorting the elements within it

Posted 26 May 2014 - 09:22 AM

Also posted at: http://www.javaprogr...html#post148597
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1