• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

illegal start of expression

Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic