Main:
package crapstest;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
rules game = new rules ();
Scanner reader = new Scanner(System.in);
System.out.println("Press any key to roll dice.");
reader.next();
}
}
Below is the code for my methods(this maybe incorrect syntax for it, please help me syntax it properly)
package crapstest;
public class rules {
public boolean getRoll(){
int d1 = (int)(Math.random()* 6 + 1);
int d2 = (int)(Math.random()* 6 + 1);
int roll = d1 + d2;
int roll2 = 0;
boolean craps = false;
//Winning Roll
if(roll == 7||roll == 11){
System.out.println("You Win!");
}
//Losing Roll
else if(roll == 2 || roll == 3 || roll == 12){
System.out.println("Sorry, you lost!");
}
do{
int die1 = (int)(Math.random()* 6 + 1);
int die2 = (int)(Math.random()* 6 + 1);
int rolls2 = die1 + die2;
if (roll == rolls2){
System.out.println("You win!");
craps = true;
}
else if(rolls2 == 7){
System.out.println("Sorry, You lose!");
craps = true;
}
}
while (craps != true);
return true;
}
}
It is a craps game so it generates a random number and uses that to determine weather or not it is a win roll or a lose roll. Im kinda stuck if i should put the segment of code in which it generates the number in my main class or the methods class. All help would be greatly appreciated. Thank you!

New Topic/Question
Reply




MultiQuote



|