Question: Java Create a simple one-player GUI dice game using two dice. The player enters a bet in a text field and then clicks a button

Java

Create a simple one-player GUI dice game using two dice. The player enters a bet in a text field and then clicks a button to enter the bet in text field and roll the dice. If the roll is 7 or 11, the player wins three times the bet. Otherwise, the player loses the bet.

//Im trying to run public class dice and see if it works can anyone help

//Public class TestDice //public static void main(String[] args){ //Dice d1=new dice();

//}

import java.awt.*; import javax.swing.*; import java.io.*; import java.util.*;

public class Dice {

private String color; private int n1,n2,n3,n4,n5,n6; private int nTime; public Dice() { } public Dice(String str) { this.color = str; } public void setColor(String str) { this.color = str; } public String getColor() { return color; } public void throwDice(int nt) { nTime = nt; for(int i = 0 ; i < nt; i++) { int dice = (int)(Math.random()*(6-1+1)+1); if(dice == 1) n1++; else if(dice==2) n2++; else if(dice==3) n3++; else if(dice==4) n4++; else if(dice==5) n5++; else if(dice==6) n6++; else ; } } } public String toString() { String out="I am "+color+" Dice Throwng "+nTime+" "; out += "Ocurrences of 1's are:"+n1+" "; out += "Ocurrences of 2's are:"+n2+" "; out += "Ocurrences of 3's are:"+n3+" "; out += "Ocurrences of 4's are:"+n4+" "; out += "Ocurrences of 5's are:"+n5+" "; out += "Ocurrences of 6's are:"+n6+" "; return out; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!