reset password
Author Message
vmarti12
Posts: 17
Posted 22:29 Oct 09, 2012 |

is there anyone who can help me with this program ??

ychan10
Posts: 7
Posted 22:53 Oct 09, 2012 |

hey How can I help???

vmarti12
Posts: 17
Posted 22:54 Oct 09, 2012 |

im having trouble trying to get the whole game set up... i know its family to the heads and tails lab, but its confusing me now that we have three integers.

 

import java.util.Scanner;

public class RockPaperScissor {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
       
        System.out.println("Let's play rock paper scissors. Enter 0, 1, or 2: ");
        int choice1 = input.nextInt();

       
        int random1 = 0 + (int)(Math.random() * ((2 - 0) + 1));
        int random2 = 0 + (int)(Math.random() * ((2 - 0) + 1));
        int random3 = 0 + (int)(Math.random() * ((2 - 0) + 1));

 

 

i dont know if im on the right track... can you tell me what im missing so far? i greatly appreciate it

ychan10
Posts: 7
Posted 23:01 Oct 09, 2012 |

I am not sure if we are in the same class.. but my class only require the comptuer generate one random number either 0, 1 or 2..

and you need to enter your guess once.. then it check if your guess match with computer..

ychan10
Posts: 7
Posted 23:01 Oct 09, 2012 |

so you don't need to generate 3 random number..

vmarti12
Posts: 17
Posted 23:03 Oct 09, 2012 |

im in cs210 tues thurs 300-600


so what youre saying is i only need just one

int random1 = 0 + (int)(Math.random() * ((2 - 0) + 1));

 

and then do if else statements afterwards?

 

could you give me an example??

ychan10
Posts: 7
Posted 23:07 Oct 09, 2012 |

yes... I just use one random number..

 

then you need the input from the user...  create some like

int user=input.nextInt()

 

vmarti12
Posts: 17
Posted 23:09 Oct 09, 2012 |

ok i got that, now what do i do in the if statements. this is the part that is always making me over think things. and once i see it, i see how easy it is..

 

another example for this please?

ychan10
Posts: 7
Posted 23:10 Oct 09, 2012 |

then compare the input in the 

 

if (statement) 

for example if (input == random1) then print  you are tied with computer..

 

vmarti12
Posts: 17
Posted 23:12 Oct 09, 2012 |

so then can i say

else if (input > random1) ??

kknaur
Posts: 540
Posted 23:15 Oct 09, 2012 |

Sometimes using compound boolean expressions can help, i.e. expressions where you use the &&, ||, ^, operators.

vmarti12
Posts: 17
Posted 23:17 Oct 09, 2012 |

if (input == random1 &&

 

 

what would go after that?

 

ychan10
Posts: 7
Posted 23:17 Oct 09, 2012 |

Oh .. forgot because 0 is rock.. 1 is paper and 2 is scissor...

 

so if (user> random1)

 

you win..

 

but keep in mind that scissor lose to rock.. 

so you need some like this

else  if ((random1== 0 ) &&  (user1 == 2)) then print computer win...

the resevse is truth too

else if ((random1==2) && (user1 ==0))  then print you win

 

Please put this before the  if (user> random1).. other you will run into error..

hope this will help.. you have like 35 min to work.. good luck

vmarti12
Posts: 17
Posted 23:18 Oct 09, 2012 |

thanksi think i got it

i really appreciate it

ychan10
Posts: 7
Posted 23:21 Oct 09, 2012 |

I gave you the hint from my past mistakes. So hope this help.. Next time you may need to start early.. some of the question require thinking.. took me like 2 hours to find out... GOOD luck