File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes illegal start of expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "illegal start of expression" Watch "illegal start of expression" New topic
Author

illegal start of expression

Kelly Frasure
Greenhorn

Joined: Mar 03, 2001
Posts: 15
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).]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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

Dave
Mikael Jonasson
Ranch Hand

Joined: May 16, 2001
Posts: 158
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: illegal start of expression