Home > Net >  How to add a roll dice function and a check guess function?
How to add a roll dice function and a check guess function?

Time:11-16

How to add a roll dice method and a check guess method?

My code:

package oui;

import java.util.Scanner;

public class dicecalc {
    
    public static void main(String args[]) {
        
        Scanner kb = new Scanner(System.in);
        
          
      int numGuess;
        

                System.out.println("Enter the number the numer the dice will roll: ");
                numGuess = kb.nextInt();
                
                int dice1=(int)(Math.random()*6 1);
                int dice2=(int)(Math.random()*6 1);
                int sum = dice1   dice2;
            
                System.out.println("Roll: total =  "   sum); 
                 {
                if (sum != numGuess) {
                    System.out.println("Sorry with a "   sum   " You LOSE :(");
                  
                } else { 
                    System.out.println("Woah!!! With a "   sum   " You WIN!!!!!!!");
                }
                }
          }
      }

I need to have this assignment resubmitted because I forgot those things but I don't know how to add it. Please help. I already have tried for days.

CodePudding user response:

Here's one possible basic layout. Replace the ??? with some code!

import java.util.Scanner;
class Main {

  public static void main(String[] args) {
    Scanner kb = new Scanner(System.in);     
        
    System.out.print("Enter the number the numer the dice will roll: ");
    int numGuess = kb.nextInt();
    
    int sum = sumOfTwoDiceRolls();

    System.out.println("Roll: total =  "   sum); 
    {
      if (!checkGuess(numGuess, sum)) {
          System.out.println("Sorry with a "   sum   " You LOSE :(");  
      } else { 
          System.out.println("Woah!!! With a "   sum   " You WIN!!!!!!!");
      }
    }
  }

  public static int sumOfTwoDiceRolls() {
    return ??? ;
  }

  public static int singleDiceRoll() {
    // Math.random() * (max - min   1)   min
    return (int)(Math.random() * (6 - 1   1)   1);
  }

  public static boolean checkGuess(int guess, int numberToGuess) {
    return ??? ;
  }
  
}
  •  Tags:  
  • java
  • Related