Question: PLEASE ONLY CODE IN JAVA AND PLEASE POST FULL CODE! **Here is a video explaining how to play the Penny Drop Game: https://youtu.be/P7tVFX03GJY Introducing JOptionPane
PLEASE ONLY CODE IN JAVA AND PLEASE POST FULL CODE!
**Here is a video explaining how to play the Penny Drop Game: https://youtu.be/P7tVFX03GJY
Introducing JOptionPane and Looping
The Learning Goals for this exercise is to interact with a user with JOptionPane and to use looping.
We will use JOptionPane windows instead of Scanner for user input and output.
Looping is used in many different ways to complete common repetitive tasks.
PowerShell or Terminal is not the most common way that users interact with programs. Windows and dialog boxes are very natural. JOptionPane will allow you to get information to and from a user.
Learning Objectives
Use of JOptionPane as a way to communicate with users.
Use variables to store data for a small game.
Create a dice to roll.
Use of loops to allow the program to continue or end or continue their turn.
Please stay within the bounds of this assignment and what we have learned so far. For this program, you do not need arrays, methods (you may use the dice method shown in class, but no other methods should be created), or any imports except:
import javax.swing.JOptionPane;
(You may use import java.util.Scanner; for debugging and development, but it is not allowed in the final version.)
What To Do
Write a program that implements the simple game, Penny Drop.
Penny drop is a simple game that requires a few pennies per player, a box, and one dice. If you are not familiar with the game, watch this:Penny Drop VideoLinks to an external site.
Make a game that is a human player against a computer. Take turns allowing the computer to finish its turn, then asking the player if they want to roll again after their first roll. Check for and announce the winner.
Make the name of the class YournameEx3
Include comments: your name, date, class, and platform(Mac or PC).
Create a Java that uses JOptionPanes to communicate with the user instead of a shell (Terminal or Powershell). The use PrintLN is OK for development or debugging, but NONE should be present in the final turned in version.
Start with a welcome screen in a JOptionPane.
Use a dialog box to welcome the user and tell them what the program does.
Use a dialog box to ask the user their name. Use their name when it is their turn, if they wing, and to thank them for playing.
Roll the dice to determine who goes first, to simplify, the tie can go to the player.
Display the desired results.
At each change of player (end of turn) display how many pennies each player has.
For each players roll, let the player know how many pennies are on top of the box (it can be between 0 and 5) and ask the player if they want to roll again or end their turn.
When the player wants to stop rolling, display the status and switch to the computers turn. (Your code can decide when the computer quits playing, either by rolling the number of a slot that already has a penny, or deciding that there are too many pennies showing)
There should be no output to the terminal or PowerShell for this example in the finished product you turn in. (It is ok to display to the terminal or PowerShell during development and/or debugging. Be sure to turn that off before turning in the program.)
Accept user input and display output through JOptionPanes - do not use System.out.print... or a scanner.
Save the modified Java code in a file called YourNameEx3.java.
Use the javac command to compile your code.
Use the java command to evaluate the results of your code.
Iterate until you are happy with the result.
Post your code on this assignment page.
Optional Ideas
These should only be attempted if the above is fully working.
Display a representation of empty and full slots after each roll.
Allow another game to be played without leaving the program, or allow user to quit.
Allow entering the starting number of pennies to be chosen at the start of the game.
Allow changing the computer from a conservative player to an aggressive player.
Game Rules
2 players, one is the computer.
EACH PLAYER NEEDS 12 Pennies: note - you can use 10 pennies if you want to make a faster game. (Fewer for development purposes.) Player indicates a human, computer is the computer. Player rolls first.
THE OBJECT OF THE GAME IS TO BE THE FIRST TO GET RID OF ALL OF YOUR PENNIES
Determine who goes first by each player rolling the single dice cube. Highest # goes first; then play proceeds in a clockwise direction. Tie goes to player.
Player rolls the die and must put a penny in the game board slot corresponding to the number shown on the die.
If the player rolls a number that already has a penny in it, they must take all of the pennies showing on the board and then the turn goes to the next player
A player must take at least one roll, but can take as many rolls as they want until they get stuck as in rule #3.
The hole at number 6 lets the penny go inside the box so you can roll as many as 6s as possible without penalty
Play continues until a player runs out of pennies and is declared the winner. The pennies are redistributed to start the next game.
**Side note: my TA used a lot of boolean statements
** This is what I have so far:
import javax.swing.JOptionPane; import javax.swing.*; class FaithLindnerEx3 { public static void main(String[] args) { JOptionPane.showMessageDialog(null,"Welcome to the Penny Drop Game!"); var name = JOptionPane.showInputDialog("What is your name?"); var output = " Welcome, " + name + "!"; JOptionPane.showMessageDialog(null, output); JOptionPane.showMessageDialog(null, "Let's get started!"); JOptionPane.showMessageDialog(null,"You have 12 pennies. Now let's roll the die!");
int option = 0; String output2 = ""; int roll;
do { roll = (1 + (int)(Math.random() * 6)); output2 = String.format("You rolled a %d Roll again?",roll); option = JOptionPane.showConfirmDialog(null,output2,"Dice roll",JOptionPane.YES_NO_OPTION); } while (option == 0); JOptionPane.showMessageDialog(null,"Thanks for rolling, " + name + "! Now it's the next player's turn!"); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
