How many methods are in this program? How do you identify a method? package crap
ID: 3638939 • Letter: H
Question
How many methods are in this program? How do you identify a method?
package crapsgame;
public class CrapsGame {
// Begin my main method
public static void main(String[] args)
{
// Display the first message
System.out.println("Roll the dice and enter the values: ");
// Declare dice
int dice1 = (int) (Math.random() * 6 + 1);
int dice2 = (int) (Math.random() * 6 + 1);
// Calculate the total of dice1 and dice2, store in roll1
// Declare rolltotals
int rolltotalone = dice1 + dice2;
int rolltotaltwo = 0;
// Let craps be true
boolean craps = true;
// Display total of dice1 and dice2
System.out.println("You rolled a "+dice1+" and a "+dice2+" which = "+rolltotalone);
// Check dice total for 7 or 11 Win Game!
if (rolltotalone == 7 || rolltotalone == 11)
// Display the output
System.out.println("You Win!!");
// Check dice total for 2, 3, or 12 Lose Game
else if (rolltotalone == 2 || rolltotalone == 3 || rolltotalone ==12)
// Display the output
System.out.println("Sorry, You Lost");
// Check dice total is not equal to 0
else if (rolltotalone != 0)
// Display the total
System.out.println("The total is "+rolltotalone);
do
{
// Let dice1 choose from the system randomly
dice1 = (int) (Math.random() * 6 + 1);
// Let dice2 choose from the system randomly
dice2 = (int) (Math.random() * 6 + 1);
// Calculate the total of dice1 and dice2
rolltotaltwo = dice1 + dice2;
// Display total
System.out.println("You rolled a "+dice1+" and a "+dice2+" which = "+rolltotaltwo);
// Check dice1 and dice2, if equal, You win!
if (dice1 == dice2)
{
System.out.println ("You win!");
// Update
craps = false;
}
// Check rolltotaltwo, if 7 You lose
else if (rolltotaltwo == 7)
{
System.out.println("You lose");
// Update
craps = false;
}
else if (rolltotaltwo != 0)
// Display total if rolltotaltwo in not 0
System.out.println("The total is "+rolltotaltwo);
// Loop ends if craps not equal to false
} while (craps != false);
} // End main
} // End class
Explanation / Answer
Methods are any sort of functions main System.out.println Math.random are 3 methods here
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.