I am currently writing a Scrabble program and working on the bag that contains all of the tiles. I have set up the tiles using a vector that stores their frequency. I am trying to iterate through the vector using a for loop but for some reason I keep getting the following error,
This happens everytime I try and iterate through the vector which is a few times. My code for the whole things is as follows,
I should mention that this is for my uni coursework and we are not allowed to use calsses from the java.util package, I was wondering if that is the reason it does not work.
Any help is very very much appreciated. Thanks very much.
Well I thought that the .length method returned how many elements there were in the vector. I have also tried tilelist.size() but that does not seem to work either. Not sure if that answers your question though, do I need to have a method in the MyVector that adds up how many there are?
If you're asking about that MyVector class you posted up there, then you can look at the code yourself and see what methods it has. You can see that it doesn't have any size() method just by looking at it. (There are two methods, but neither of them are called size().) Likewise you can see that it doesn't have a length variable. (It has two variables but neither are called length.)
But wait! This MyVector class might be a subclass of something which has one of those things! But no... it's only a subclass of Object, which doesn't have a size() method or a length variable.
So I don't know where you expected those methods to come from. Is that your class? Then it's up to you to write them. They won't appear by magic just because you try to use them.
You would find it easier to set up the tiles with chars in your for loop. You mightn't believe it, but you can alter it toHave you been told you use Vector rather than the more efficient ArrayList? Do you know how to put the letters, counts and tile values into a Map?