Together with a classmate in my Advance Java class at Cal Poly Pomona, I built a simple Java Web Casino App that allows users to play poker, craps, and hi-lo. This assignment also happened to be part of a competition, with the first place to receive some extra credit. I am happy to report we got first prize, self high five. For this project we implemented the model, view, controller design aspect of Java and included a MySQL database to hold the data.
- Play Games
- View Game Leaderboard
- View Personal Game Statistics
- View List of
- Delete, Update, or Insert to any Table
- End User Privileges
Tools and Languages Used
- NetBeans IDE
- MySQL Workbench
- Java Server Pages (JSP)
- Java Servlets
Model View Controller (MVC)
- A browser sends a request to a servlet either using a GET or POST method.
- A servlet receives the request and creates an instance of a database model.
- The database model then executes queries and sends any requested data to the servlet.
- The servlet prepares a request object with appropriate variables to be used by a view.
- The view then sends an html document back to the browser.
User Table – Holds information about every user that creates a login.
Game Table – Holds basic information about each game.
Transaction Table – A row is added every time a user plays a game and logs the game played, user who played, amount won or lost. This table is queried to load statistics about the user’s performance.
The first page you see is the login page, you can also choose the existing user login. If username already exist the app will return an error and you will be prompted to create another username.
Choose Game Page
After login you will see a page with options to choose a game to play or to view leader-boards.
User Statistics Page
On the top right of the page user can click on their name and see a page with statistics on their performance.
A separate Java Server Page JSP file was created to load the navbar to every page. In the code, I included Java Standard Tag Language JSTL to check if the user is an admin. It then either loads a span with a link to the admin console when appropriate.
When user request a leaderboard the stat servlet checks the action attribute and uses the database model to run a script and return a list of users who have played that game.
I used Github for version control on this project and it was the first time using it as a team. That brought on a couple more challenges to the project but the benefits definitely outweighed the setbacks. I can assure you we had a few merge conflicts and took some time to fix them but I feel like it was a great learning experience. Another note, I discovered that NetBeans has cool and easy to use Github controls.
I can finally see the full power that Java has to offer. I have now taken 4 different classes on Java alone, more on other programming concepts like databases and ux design, and this was an enlightening experience into how using Java as a backend manager can bring its heavy lifting power to web development.