Results 1 to 4 of 4
  1. #1
    melina2134 is offline Member
    Join Date
    Oct 2014
    Posts
    1
    Rep Power
    0

    Default beginner needs help with program!

    this program is supposed to let the user play rock (0) paper (1) scissors (2) with the computer however this error message come up: Compilation Errors Detected

    Line: 14
    '.class' expected

    help please im not sure what this means?

    import java.util.*;
    import java.util.Scanner;

    public class Lab3
    {

    public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    int scissor = 0;
    int rock = 1;
    int paper = 2;
    Random ran = new Random();
    int x = ran.nextInt(3) + 0;
    int randomIndex = int computer;
    int guess = input.nextInt();
    if (guess == computer){
    System.out.println("It's a draw!");
    }
    else {
    if (guess < computer)
    System.out.println("You lost. Better luck next time!");
    }
    if (guess > computer)
    {
    System.out.println("You won!");
    }
    }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    14

    Default Re: beginner needs help with program!

    Can you please format your code and use the code tags?

    I notice a few mismatched curly brackets, but that might be because you aren't using them on a single-line if statement. Hard to tell without seeing formatted code.

    What line is the error on?

    Also, what is this line supposed to do:

    int randomIndex = int computer;
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    JoePenguin is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Re: beginner needs help with program!

    I take it that 'computer' is suppose to represent the computer competition and therefore should be set to the random that you call 'x'.
    you create the random which is to choose whether the computer has rock, paper or scissors but the random is never used.
    To make it work you need to replace the line:
    int randomIndex = int computer;
    with:
    int computer = x;
    Also the concept of the code will not work as paper is lager than scissors but scissors is suppose to win over paper.

    i would look into this tutorial: How to Make a Rock, Paper, Scissors Game in Java (with Pictures)

    this tutorial shows how to implement methods to seperate different actions.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: beginner needs help with program!

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. help with beginner program
    By newcomer123 in forum Eclipse
    Replies: 1
    Last Post: 09-15-2014, 11:58 PM
  2. Could a beginner make a program like this?
    By Trouble919 in forum New To Java
    Replies: 5
    Last Post: 02-23-2013, 08:54 AM
  3. Replies: 4
    Last Post: 01-30-2012, 02:21 PM
  4. Triangle program for beginner
    By shawnx715 in forum New To Java
    Replies: 18
    Last Post: 11-15-2011, 12:40 PM
  5. Beginner Needs Help w/ Program for School
    By badness in forum New To Java
    Replies: 2
    Last Post: 11-24-2007, 07:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •