Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. Difficulty searching element in an Array

Difficulty searching element in an Array

Scheduled Pinned Locked Moved Java
databasecomalgorithmsdata-structurestutorial
1 Posts 1 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sifuyipe
    wrote on last edited by
    #1

    Been messing around for hours and eventually decided to seek the assistance of the internet. I am trying to make a program where I/the user can add elements into an array (Name, age gender). Once elements have been added to the array, I want to then be able to search a String (name) to find the desired name I am after in the array. The context of the program is adding Climbers to a Climber Database (just an array) of who has climbed what mountain (haven't attempted adding the mountain stuff yet). In what I've written so far, I keep getting the return null, saying that the searched String cannot be found. I have a feeling that I am failing to pass the parameters of the added element in the array. For example, I add a 'climber' with the name John, 19, Male in the Climber Class. I then go to the ClubStats class to getClimber and search "John", the only one in the array and I receive a null.. FYI I am using BlueJ here so at a serious basic level.

    /**
    * Write a description of class Climber here.
    *
    * @author (your name)
    * @version (a version number or a date)
    */
    public class Climber
    {
    // Instance variables.
    // The climber name.
    private String name;
    // The climber age.
    private int age;
    // The climber gender.
    private String gender;

    /\*\*
     \* Constructor for objects of class Climber
     \*/
    public Climber(String newName, int newAge, String newGender)
    {
        // Initialise instance variables.
        name = newName;
        age = newAge;
        gender = newGender;
    }
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups