I'm just trying to figure out this homework and could use some help. NOT LOOKING FOR ANSWERS, just a better understanding. I'm very very new to coding, using jGRASP java. The teacher told us to create this game that generates an output similar to this.
Round 1:
• Player A rolls: 1,2, the highest number is 21 • Player B rolls: 2,1, the highest number is 21 • Result: draw
• Round 2: • Player A rolls: 2,5, the highest number is 52 • Player B rolls: 6,8 the highest number is 86 • Result: Player B wins
• Round 3: • Player A rolls: 1,9, the highest number is 91 • Player B rolls: 9,9 the highest number is 99 • Result: Player B wins
• Final Result: Player B wins!!!
Do I have to declare the numbers as Strings to concatenate them? and do I use if else statements? Specifically, I'm confused on how to arrange the two numbers if one is greater than the other so the greater number will be placed in front.
Anything helps, thank you guys.
Have a good day!
import java.util.Scanner;
import java.util.Random;
public class beatThat
{
public static void main(String[] args)
{
Random r1 = new Random();
Random r2 = new Random();
Random r3 = new Random();
Random r4 = new Random();
int die1 = r1.nextInt(6) + 1;
int die2 = r2.nextInt(6) + 1;
int die3 = r3.nextInt(6) + 1;
int die4 = r4.nextInt(6) + 1;
System.out.println("ROUND 1");
System.out.println("Player A rolls: " + die1 + " and " + die2 +".");
System.out.println("Player B rolls: " + die3 + " and " + die4 +".");
if(die1 >= die2)
{
System.out.println("Player A's highest number is: " + die1 + die2);
}
else if(die2 >= die1)
{
System.out.println("Player A's highest number is: " + die2 + die1);
}
if(die3 >= die4)
{
System.out.println("Player B's highest number is: " + die3 + die4);
}
else if(die4 >= die3)
{
System.out.println("Player B's highest number is: " + die4 + die3);
}
}
}