Click here to Skip to main content
15,886,578 members
Home / Discussions / Java
   

Java

 
Questionhow to start learning java Pin
Member 1383037827-May-18 23:23
Member 1383037827-May-18 23:23 
AnswerRe: how to start learning java Pin
Richard MacCutchan28-May-18 22:16
mveRichard MacCutchan28-May-18 22:16 
QuestionNeed help choosing test API Pin
Member 1384132023-May-18 8:37
Member 1384132023-May-18 8:37 
QuestionMessage Closed Pin
10-May-18 0:44
Andrew Steves10-May-18 0:44 
AnswerRe: Error in Integer mode Pin
Richard MacCutchan10-May-18 1:16
mveRichard MacCutchan10-May-18 1:16 
GeneralRe: Error in Integer mode Pin
Richard Deeming10-May-18 1:26
mveRichard Deeming10-May-18 1:26 
GeneralRe: Error in Integer mode Pin
Richard MacCutchan10-May-18 1:27
mveRichard MacCutchan10-May-18 1:27 
QuestionHalp please? Dice roll game. Pin
Gril13376-May-18 7:01
Gril13376-May-18 7:01 
Hey guys!

I'm just trying to figure out this homework and could use some help. Not looking for answers really, 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.

Java


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);
}

}
}
Java


Anything helps, thank you guys.

Have a good day!

modified 6-May-18 14:51pm.

AnswerRe: Halp please? Dice roll game. Pin
Richard MacCutchan6-May-18 21:52
mveRichard MacCutchan6-May-18 21:52 
QuestionSolving symmetric tree problem by recursive solution Pin
ElenaRez6-May-18 6:52
ElenaRez6-May-18 6:52 
AnswerRe: Solving symmetric tree problem by recursive solution Pin
Richard MacCutchan6-May-18 21:44
mveRichard MacCutchan6-May-18 21:44 
QuestionAsk a Question All Questions All Unanswered Mine FAQ I need to compare one file each line with other file all lines which separated by two colon separate .if matches with names I need print matched one in java Pin
Member 138094092-May-18 23:07
Member 138094092-May-18 23:07 
AnswerRe: Ask a Question All Questions All Unanswered Mine FAQ I need to compare one file each line with other file all lines which separated by two colon separate .if matches with names I need print matched one in java Pin
Richard MacCutchan3-May-18 0:44
mveRichard MacCutchan3-May-18 0:44 
QuestionDeep copy of List<> without knowing specific list type Pin
jackbrownii30-Apr-18 10:55
professionaljackbrownii30-Apr-18 10:55 
AnswerRe: Deep copy of List<> without knowing specific list type Pin
Manish K. Agarwal27-May-18 21:32
Manish K. Agarwal27-May-18 21:32 
QuestionStudent needing assistance while loop Pin
Victor McNeal21-Apr-18 9:15
Victor McNeal21-Apr-18 9:15 
AnswerRe: Student needing assistance while loop Pin
Richard MacCutchan21-Apr-18 20:56
mveRichard MacCutchan21-Apr-18 20:56 
QuestionJava JUnit test error Pin
CHUCHU YAO20-Apr-18 13:23
CHUCHU YAO20-Apr-18 13:23 
AnswerRe: Java JUnit test error Pin
Richard MacCutchan20-Apr-18 20:43
mveRichard MacCutchan20-Apr-18 20:43 
AnswerRe: Java JUnit test error Pin
jschell21-Apr-18 6:31
jschell21-Apr-18 6:31 
GeneralRe: Java JUnit test error Pin
Richard MacCutchan21-Apr-18 20:58
mveRichard MacCutchan21-Apr-18 20:58 
QuestionJAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Member 1378720218-Apr-18 20:59
Member 1378720218-Apr-18 20:59 
QuestionRe: JAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Richard MacCutchan18-Apr-18 21:51
mveRichard MacCutchan18-Apr-18 21:51 
AnswerRe: JAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Member 1378720219-Apr-18 0:54
Member 1378720219-Apr-18 0:54 
GeneralRe: JAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Richard MacCutchan19-Apr-18 1:02
mveRichard MacCutchan19-Apr-18 1:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.