I just wrote this dice simulation code
This is as far as ive gotten but i want to make it do a comparison. I want it to take the results and after "rolling" the die 5 times add the results. If the sum is over 22 then I want it to print the player wins. If not than I want it to say the player didnt win. My question is "is what I have so far ok? will my code loop 5 times for the throwing of the dice? and how do i make the neccesary modification to make I run the way I desire?"
/*
* Author: Adriann Guy
* Class: COMT 20011
* Lab: Lab 4
* Date:
* Purpose: This program simulates 5 dice
*/
import java.util.*;
import java.lang.*;
public class Fivedice
{
public class Die{
int faceValue;
public Die(){
this.faceValue = roll();
}
public int getFaceValue(){
return this.faceValue;
}
public void displayLine(){
System.out.println(this.faceValue);
}
private int roll(){
return ((int)(Math.random() * 100) % 6 + 1);
}
}
public Fivedice() {
Die dieOnePlayer = new Die();
Die dieOneCPU = new Die();
Die dieTwoPlayer = new Die();
Die dieTwoCPU = new Die();
Die dieThreePlayer = new Die();
Die dieThreeCPU = new Die();
dieOnePlayer.displayLine();
dieOneCPU.displayLine();
dieTwoPlayer.displayLine();
dieTwoCPU.displayLine();
dieThreePlayer.displayLine();
dieThreeCPU.displayLine();
System.out.print("CPU got dieOneCPU , dieTwoCPU , dieThreeCUP");
System.out.print("Player got die dieOnePlayer , dieTwoPlayer , dieThreePlayer");
}
public static void main(String[] args)
{
Fivedice fd = new Fivedice();
}
}
This is as far as ive gotten but i want to make it do a comparison. I want it to take the results and after "rolling" the die 5 times add the results. If the sum is over 22 then I want it to print the player wins. If not than I want it to say the player didnt win. My question is "is what I have so far ok? will my code loop 5 times for the throwing of the dice? and how do i make the neccesary modification to make I run the way I desire?"