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;
}
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
eschew obfuscation
I just read the restrictions again, and I am not meant to use LinkedLists :s
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
Forum Rules
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
Bookmarks