Results 1 to 7 of 7
  1. #1
    mike2452 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default Array help please

    Hi there
    I have a scenario where a wildlife observer is looking for animals in the wild. The observer must enter a number 1-8 depending on the animal he sees. which could look like this
    1
    4
    3
    3
    1
    8
    4
    2
    3
    and so on
    I need to make an array with 7 animals. hippo, cheetah, buffalo, monkey, zebra, tiger, snake and Rhino

    I need to attach these animals to an array 1 - 8.
    then I want to use the scanner tool so the user can enter the numbers in at random according to what animal he sees.
    Also each animal in the array needs a counter so it can increment how many times the observer sees the particular animal. then if the user presses 0 a summary of data will come up.

    Im so stuck on this can anyone please help??

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Can an observer see different sorts of animals? e.g. can s/he see two hippos and three cheetahs? Or is only one sort of animal visible at a certain moment in time? Pleae specify.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    mike2452 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Hi Jos
    Very unrealistically yes the observer only sees one at a time, so if he sees two rhinos it needs to be inputted like
    2
    2
    if that makes sense

    thanks

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What have you tried so far? Do you need to use an array? A map could be helpful in a situation like this.

  5. #5
    mike2452 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Yeah Im have to use an array, (Not 2 dimensional)
    Its meant to be straight forward but im really new to this. I have done it like this so far
    vehicle = new int[7];
    Scanner scanner = new Scanner(System.in);
    Animal[0] = 1;
    Animal[1] = 2;
    Animal[2] = 3;
    Animal[3] = 4;
    Animal[4] = 5;
    Animal[5] = 6;
    Animal[6] = 7;
    Animal[7] = 8;
    However the scanner doesn't pick up the digits when i type them in. I also need to have a counter for each and that needs to increment each time a number is entered if that makes sense. Am i on the right track?

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Your scanner line simply creates the object, however; it doesn't actually use it. Your pseudocode should look something like this

    Java Code:
    create scanner
    create array of size x
    loop
      get input from user with scanner
      fill slot of array
    end loop
    This is a very basic representation. How are people supposed to know which type of animal goes in which array slot?

  7. #7
    mike2452 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Ahh missed that part, They know what number goes with the animal. Lets assume the observer sees a rhino he knows to press 5

Similar Threads

  1. convert byte array into char array
    By kgkamaraj in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 11:32 AM
  2. Replies: 0
    Last Post: 05-12-2011, 07:04 PM
  3. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  4. Replies: 2
    Last Post: 09-06-2010, 01:03 AM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •