• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

BlackJack Game Initial code

 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Player:

Dealer:

Regular Player:

Hand:

BlackJackGame:


BlackJackLauncher:


Card:

CardUtilities:

Deck:

InputUtilities:
 
Bartender
Posts: 15737
368
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you branch off from the master branch of our repository, and merge your work in. Try to minimize impact unless you have good arguments for it (for instance, if you decide to create a new Card class in a different package rather than updating the existing Card class).

When you're happy with your merge, create a pull request and you will get an automated review from our code analysis. The team will comment on anything that code analysis didn't pick up.
 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any luck?
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay as mentioned in Contributing I created a personal test branch and added my whole project ( which looks weird since added unnecessary files too, It's easy in Git bash way to add those in .gitignore file than Eclipse ) which I posted above. I did this using Eclipse IDE.

I find It difficult to copy the structure of project you created. I learned most of Git commands using Git bash and documented them with examples too so took little more time sorry for that. I find It is much easier than using Eclipse may be I couldn't find a good tutorial on how to use Eclipse for Github?

So the class we have in our master branch Cards is nothing but a Deck class? which I have in my code hope I'm correct.  I want to add new classes Player and It's sub classes Dealer and RegularPlayer which may not be same as It's in above code for features/feature-name for features.

It is easier for me to create a file and write code in Eclipse and copy paste that file in C:\Users\GANESH\git\Blackjack\core\src\main\java\com\coderanch\blackjack   then use Git bash to add file to stage area then commit to local repo then push to remote repo ? what will you suggest? I'm feeling a bit awkward now cause of dearth of knowledge regarding Git and all.
 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem here is that you're not using Maven to build your project. Eclipse IDE for Java Developers comes with native Maven support.

Delete the projects from your workspace and also delete the .settings/ folder and the .classpath and .project files. In the "File" menu of Eclipse, select "Open Projects from File System...". Eclipse will automatically detect that Blackjack and the core module are Maven projects.

You need to update the .gitignore to ignore .settings/, .classpath and .project as Eclipse will generate those from the Maven POM, and auto-generated files should not be part of the source repository.

Move your classes to the appropriate packages in the core/src/main/java folder. Instead of writing main() methods to test your code, write test cases inside the core/src/test/java folder. You can execute your test cases by running the "Coverage" action in Eclipse on the core module.

If you want to add a user interface, add a new module to the project. The "core" module is for the basic game logic of blackjack. I suggest you add a new module named "cli" where you can add classes for interacting with the console.

If you get stuck on any of these instructions, let us know.
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:The problem here is that you're not using Maven to build your project. Eclipse IDE for Java Developers comes with native Maven support.

Ah! I see, now got that

Delete the projects from your workspace and also delete the .settings/ folder and the .classpath and .project files. In the "File" menu of Eclipse, select "Open Projects from File System...". Eclipse will automatically detect that Blackjack and the core module are Maven projects.

Seems I did as you suggested.

Move your classes to the appropriate packages in the core/src/main/java folder. Instead of writing main() methods to test your code, write test cases inside the core/src/test/java folder. You can execute your test cases by running the "Coverage" action in Eclipse on the core module.

Now things are getting clear about Maven and JUnit ( not thoroughly but at least got what they are about ) writing simple classes using Maven and testing them using JUnit locally. Very soon will add a Player class in core/main... module, hopefully with test class of It as well in test/....

If you want to add a user interface, add a new module to the project. The "core" module is for the basic game logic of blackjack. I suggest you add a new module named "cli" where you can add classes for interacting with the console.

Added a module cli ( having core as parent ), appears added correctly.
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In screenshot cliModulePart you can see the red round which has .java files in packages where I can create new Java classes and edit them too and blue rounded part seems folder view of project? where I think we can't create new Java files because right clicking on It shows menu shown in menu screenshot but If you look at screenshot coreModulePart which has only folder view part why there is no such packages which we have rounded in red color in cliModulePart screenshot?
cliModulePart.png
[Thumbnail for cliModulePart.png]
coreModulePart.jpg
[Thumbnail for coreModulePart.jpg]
menu.jpg
[Thumbnail for menu.jpg]
 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You created your "cli" module inside of the "core" module. The "src" folder that you can't create new classes in is actually the source folder for the "core" module.

The command line interface should not be part of the core module, but it should be a separate submodule of the Blackjack project. It may use the classes from the core module by declaring a dependency on it in the POM.
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You created your "cli" module inside of the "core" module. The "src" folder that you can't create new classes in is actually the source folder for the "core" module.

I think I created separate module cli correctly? but the POM file of core module showing an error "failed to read artifact descriptor for org.hamcrest:hamcrest-library.jar:1.3"
CorePOMError.jpg
[Thumbnail for CorePOMError.jpg]
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I did

In Eclipse Git Repositories window:
cloned Git repository from our Github  link https://github.com/CoderanchCorral/Blackjack.git since I created a separate branch named Ganesh and have to make changes in that only so I just cloned that branch only but not the master, is that correct? Or have to clone master branch too? see in the screenshot.

After that imported project by right click on repository shown in another screenshot then imported two Maven projects Blackjack and Blackjack/core    hope did correct?
BranchSelection.jpg
[Thumbnail for BranchSelection.jpg]
ImportProject.jpg
[Thumbnail for ImportProject.jpg]
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way I'm wondering how members of a project team communicate how many classes Or objects going to be there in the project?  I mean not just about objects Or classes but the flow of project, methods etc. not sure I'm able to convey what I meant. How they coordinate because everyone things differently?

As Pete already posted objects in this project here  I also drew UML class diagram on ruff page and object were almost same. I think there is Player class which will have sub classes Dealer and RegularPlayer ( You can suggest good meaning full name for this) but I couldn't find more common fields Or methods (at least by now) of Dealer and RegularPlayer to be declare Or defined in Player class so they will be inherited by both sub classes. Do you still think we suppose to create a Player class having Dealer and RegularPlayer as sub classes?

 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Patekar wrote:but the POM file of core module showing an error "failed to read artifact descriptor for org.hamcrest:hamcrest-library.jar:1.3"

I solved this by creating a System variable named M2_HOME and Its value is the location of Maven folder i.e. on my system It's C:\Program Files\Apache Software Foundation\apache-maven-3.5.4  and then in System variables appended the path of maven bin folder to PATH variables value i.e. %M2_HOME%\bin;
 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Patekar wrote:By the way I'm wondering how members of a project team communicate how many classes Or objects going to be there in the project?  I mean not just about objects Or classes but the flow of project, methods etc. not sure I'm able to convey what I meant. How they coordinate because everyone things differently?


Well, normally we would take a look at our backlog to see what issues we have to resolve, and then assign an issue to a contributor. For simple bugfixes or enhancements, you would probably just immediately add new types as you see fit, and then let other members review them in a pull request. For large enhancements, you may want to create a technical design first (which might include a class diagram) which other contributors would comment on before you start writing code.

So really, the person who is assigned to the issue makes suggestions for new types and methods etc., but other contributors will always have a chance to review. The problem is that our backlog isn't filled with issues yet, which is probably something we should work on.

I think there is Player class which will have sub classes Dealer and RegularPlayer ( You can suggest good meaning full name for this) but I couldn't find more common fields Or methods (at least by now) of Dealer and RegularPlayer to be declare Or defined in Player class so they will be inherited by both sub classes. Do you still think we suppose to create a Player class having Dealer and RegularPlayer as sub classes?


I think you're going overboard with inheritance. I think we only need a Player class that encapsulates a name, a hand and a Strategy. At the appropriate moments, the game will ask each player's strategy to come up with a choice based on the current hands of the player and the dealer. There would then be different strategies such as DealerStrategy (which makes a choice based on house rules) and HumanPlayerStrategy (which blocks until the player has input a choice). For a first version, you can just implement one strategy that always hits and lets the player go bust. More advanced strategies can be added in later pull request.
 
reply
    Bookmark Topic Watch Topic
  • New Topic