This program returns an illegal start of expression error and refers to public Shuffle(). Why is this happening? I want to use this method in another class.
(edited by Cindy to format code)
[This message has been edited by Cindy Glass (edited July 04, 2001).]
Joined: May 10, 2001
Kelly A couple of things about your code: Your shuffle method is inside of your main method. You need to move it out of there and then give it a return type. When you move it out you'll get compiler errors because then your shuffle method wont be able to see the cards array which is declared locally to your main method. You can either pass the cards array to shuffle 'shuffle(cards);' or make cards a static variable of the deck class. (Every deck object would be the same right? Unless you are going to expand this to cover things like euchre decks, pinnochle decks, etc - in that case make Deck an abstract class then you'd subclass it with NormalDeck, EuchreDeck etc). In yoour case it's probably easier to just consider this a normal deck, in which case it'll always have 52 cards. So you can make cards a static class variable, shuffle could then be a static method that shuffles your cards. You'll also have to move DECKSIZE out of main too. If you do those things then you can shorten your main method and create a static initializer block to fill your cards array. Then, in main, all you'd have to do is call your methods to manipulate your Deck. Check this out, I changed some of your code to show what I mean...
some people don't like having their code changed, sorry if it upsets you, but I'm not the best at explaining what I'm saying sometimes, so it's easier to show you. If this is a school assignment you might be limited to certain things the teacher told you you had to do, if thats the case then ignore anything I wrote that you're not allowed to do. hope this helps, if you have any questions let me know... Dave
Joined: May 16, 2001
I guess the reason you get that error is because your shuffle-method doesn't have a returntype (look at Dave's code, he's put one in). Remember, only constructors have no returntype, all other methods must claim to return something, even if that something is "void". /Mike