Question: Hi, my question is about how to compile a java file on your PC, and be able to run programs. Please a detailed description and

Hi, my question is about how to compile a java file on your PC, and be able to run programs. Please a detailed description and steps to follow would be greatly appreciated thank you so much in advance.

A code I want to test is below:

import java.util.Random;

public class Dice

{

public static void main(String[] args) {

Random r=new Random();

int score1=0;//score of player 1

int score2=0;//score of player 2

boolean turn = true;

while(score1<75 && score2<75){

int roll1=r.nextInt(6)+1;

int roll2=r.nextInt(6)+1;

if(turn){

System.out.println("Player 1 rolls a "+roll1+" and a "+roll2);

score1+=roll1+roll2;

if(roll1!=roll2)

turn=false;

else{

while(roll1==roll2 && score1<75)

{

roll1=r.nextInt(6)+1;

roll2=r.nextInt(6)+1;//integer between 1 and 6

System.out.println("Player 1 has "+score1+" Player 1 gets to roll again Player 1 rolls a "+roll1+" and a "+roll2);

score1+=roll1+roll2;

}

turn=false;

}

System.out.println("Player 1 now has "+score1);

}

else{

System.out.println("Player 2 rolls a "+roll1+" and a "+roll2);

score2+=roll1+roll2;

if(roll1!=roll2)

turn=true;

else{

while(roll1==roll2 && score2<75)

{

roll1=r.nextInt(6)+1;

roll2=r.nextInt(6)+1;//integer between 1 and 6

System.out.println("Player 2 has "+score2+" Player 2 gets to roll again Player 2 rolls a "+roll1+" and a "+roll2);

score2+=roll1+roll2;

}

turn=true;

}

System.out.println("Player 2 now has "+score2);

}

}

if(score1>=score2){

System.out.println("Player 1 wins with a total of "+score1);

}

else{

System.out.println("Player 2 wins with a total of "+score2);

}

}

}

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 Programming Questions!