Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Arrays and array list

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Arrays and array list

    Creating a name class for monsters using arrays and array list. The goal is to randomize the monster names that are being generated. Any help would be greatly appreciated. Thank you.

    package character;
    import utility.SingleRandom;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Arrays;


    /** Creates a name class for the monsters
    /*
    *
    * Robert Rhinebeck
    * CS 140 B 56
    * Assignment 3
    */
    public class Names
    {
    // instance variables
    private final String nameList;

    // class variables
    private static final String [] MONSTERNAMES = {"Cletis","Gomez","Pritus","Selus","Teether"};
    //private static final int [] NUMBERNAMES = NUMBERNAMES.length;
    private static final int [] NUMBERNAMES = 5;
    MONSTERNAMES = new int[NUMBERNAMES];



    //Static Variables

    //This is the single instance accessed by members of
    // other classes via the getInstance() factory method
    private static Names instance;
    static //static initializer: This instantiates it once
    {
    instance = new Names();
    }
    ArrayList<String> namesList = new ArrayList<String>();

    /** Constructs a names list with monster name array
    */
    private Names()
    {
    List<String> listMonsters = Arrays.asList(MONSTERNAMES);

    }
    private Names ArrayList(Collection<String>listMonsters)
    {

    }
    // Instance methods
    /** Gets max names to start in array
    /*
    * @return NUMBERNAMES
    */
    // accessors
    private int getMaxNamesToStart()
    {
    return NUMBERNAMES;
    }

    /** Gets the current number of names in the array
    * return listMonsters
    */
    public int getNumberOfNames()
    {
    return listMonsters;
    }
    /** Gets the name of the monster
    * @return nameList
    */
    public String getName()
    {
    return MONSTERNAMES[2];
    }
    /** finds the name of the monster
    * @return index[MONSTERNAMES]
    */
    public String findName()
    {
    return index[MONSTERNAMES];
    }
    /** predicate or boolean for name
    * @return name
    */
    public boolean hasName()
    {
    return MONSTERNAMES.equals(nameList);

    }


    public hasNames()
    {
    return MONSTERNAMES.equals(listMonsters);
    }



    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Arrays and array list

    goal is to randomize the monster names that are being generated.
    Put the name Strings in a list and randomize it using the Collections class's shuffle() method.

    If you are creating the names, what do you mean by "randomize"?

  3. The Following User Says Thank You to Norm For This Useful Post:

    rob17 (February 19th, 2012)

  4. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Arrays and array list

    Quote Originally Posted by Norm View Post
    Put the name Strings in a list and randomize it using the Collections class's shuffle() method.

    If you are creating the names, what do you mean by "randomize"?
    We are using the Singleton Random class for this assignment. I think we are using one instance in the names class to randomize the monster names. Thank you for reviewing my post.

Similar Threads

  1. Array List of Array Lists working for first item but not for second.
    By javapenguin in forum Collections and Generics
    Replies: 6
    Last Post: February 15th, 2012, 05:12 PM
  2. Array List
    By nadirkhan in forum Collections and Generics
    Replies: 6
    Last Post: September 9th, 2011, 09:39 AM
  3. Basic array list
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 24th, 2011, 11:51 AM
  4. Array List Doubt
    By mhnganesh in forum Collections and Generics
    Replies: 2
    Last Post: July 12th, 2010, 10:21 AM
  5. Merging Arrays Vs. Linked List.
    By Kumarrrr in forum Collections and Generics
    Replies: 1
    Last Post: March 1st, 2010, 03:20 AM