This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How do I play again as the same 'player'?  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I currently have a Player class private instances, getters, and setters as well as a game class.

For the game, I ask the player for their name. It is saved in the object class. Every player has a $500 balance.
The game is called 21 of Dice and basically, it is like Blackjack in a sense that if you happen to beat the dealer (or computer) you win $100 and if you lose or tie, you lose $50.

When I play the game each time, it is creating a new player. I want it to be possible that I want to play as the same player with the updated balance. Any help would be greatly appreciated.

Here is my Player class:





Here is my Game class:


 
Rancher
Posts: 515
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of calling your play21method from your playAgainmethod, call your playAgainmethod from your play21Method, make it return a boolean and put your playmethod, except for the playercreation in a do whileloop that calls the playAgainmethod, when the player presses y it reurns true and otherwise false
 
Rancher
Posts: 3317
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you post the code that you are executing?
How do you execute the program?

I don't see where the playGame method is called.
 
Daniel Demesmaecker
Rancher
Posts: 515
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Illustrate:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!