Help Change Class Please


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Help Change Class Please

  1. #1
    Join Date
    Mar 2005
    Posts
    3

    Post Help Change Class Please

    Hello Members,
    I would like to find out if anyone is nice enough to help me remove the ArrayList class from this code completely and replace it with something else that is not either of the following:

    HashSet, LinkedHashSet, TreeSet, ArrayList, LinkedList, HashMap, TreeMap, LinkedHashMap, WeakHashMap, IdentityHashMap, Arrays, Collections, Hashtable, Vector

    Code:
    package files;
    
    import wrabble.*;
    import java.util.ArrayList;
    
    public final class TileBag implements ITileBag
    {
        public TileBag()
        {
            tiles = new ArrayList();
            addTiles('A', 1, 9);
            addTiles('B', 3, 2);
            addTiles('C', 3, 2);
            addTiles('D', 2, 4);
            addTiles('E', 1, 12);
            addTiles('F', 4, 2);
            addTiles('G', 2, 3);
            addTiles('H', 4, 2);
            addTiles('I', 1, 9);
            addTiles('J', 8, 1);
            addTiles('K', 5, 1);
            addTiles('L', 1, 4);
            addTiles('M', 3, 2);
            addTiles('N', 1, 6);
            addTiles('O', 1, 8);
            addTiles('P', 3, 2);
            addTiles('Q', 10, 1);
            addTiles('R', 1, 6);
            addTiles('S', 1, 4);
            addTiles('T', 1, 6);
            addTiles('U', 1, 4);
            addTiles('V', 4, 2);
            addTiles('W', 4, 2);
            addTiles('X', 8, 1);
            addTiles('Y', 4, 2);
            addTiles('Z', 10, 1);
        }
    
        private void addTiles(char c, int i, int j)
        {
            for(int k = 0; k < j; k++)
                tiles.add(new Tile(c, i));
    
        }
    
        public Tile removeTile()
        {
            if(tiles.size() == 0)
            {
                return null;
            } 
            
            else
                
            {
                int i = (int)(Math.random() * (double)(float)tiles.size());
                Tile tile = (Tile)tiles.remove(i);
                return tile;
            }
        }
    
        public void addTile(Tile tile)
        {
            tiles.add(tile);
        }
    
        public boolean isEmpty()
        {
            return tiles.size() == 0;
        }
        
        ArrayList tiles;
    }

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    I have this.

    This is a 'list' class that is a linked list with que, stack, hashtable and arraylist
    functionalities. It also includes its own exception and listener class.

    I have supplied a driver class so you can check how it can be used.
    Attached Files Attached Files
    eschew obfuscation

  3. #3
    Join Date
    Mar 2005
    Posts
    3
    I just read the restrictions again, and I am not meant to use LinkedLists :s

  4. #4
    Join Date
    Mar 2005
    Posts
    3
    Just found out I can use primitive arrays like:

    array1[index]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center