Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Need help ASAP (Submission is in two hours) :(

  1. #1
    Junior Member Rods's Avatar
    Join Date
    Sep 2014
    Location
    New York
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help ASAP (Submission is in two hours) :(

    /*
    2. A run is a sequence of adjacent repeated values.
    write a program that generates a sequence of 20 random die tosses
    (between 1 and 6) in an array and prints the die values, marking
    the runs by including them in parentheses, like this
    1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 3 1
    Use the following pseudocode algorithm:
    set a boolean variable inRun to false
    For each valid index i in the array
    ifinRun
    if value[i] is different from the preceding value
    print )
    inRun=false
    if not inRun
    if value[i] is the same as the following value
    print (
    inRun=true
    print value[i]
    ifinRun
    print )
    */

    import java.util.*;
    public class dieToss
    {
     public static void main(String[] args)
     {
      Random rand=new Random(System.in);
      int[] value=new int[20];
      for(int i=0; i<dieToss.length; i++)
       {
         value[i]=rand.nextInt(6)+1;
         boolean inRun=false;
     
     if (inRun)
        {
        if (value[i]!=value[i-1])
    	{
       System.out.println(" )");
       }
       } 
       if(value!=inRun)
     {  
       if(value[i]==value[i+1])
       {
       System.out.println(" (");
       }
     }  
         inRun=true;
         {
       System.out.println(value[i]);
       }
     if (inRun)
       {
        System.out.println(" )");
       }  
      }
     }
    }

    I am getting This error
    dieToss.java:6: error: incompatible types: InputStream cannot be converted to long
    Random rand=new Random(System.in);
    ^
    dieToss.java:8: error: cannot find symbol
    for(int i=0; i<dieToss.length; i++)
    ^
    symbol: variable length
    location: class dieToss
    dieToss.java:20: error: incomparable types: int[] and boolean
    if(value!=inRun)
    ^
    Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
    3 errors
    Last edited by Rods; October 1st, 2014 at 11:16 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,381
    Thanks
    53
    Thanked 2,397 Times in 2,350 Posts

    Default Re: Need help ASAP (Submission is in two hours) :(

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Which of the error messages are you having problems understanding?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Need help ASAP (Submission is in two hours) :(

    Please post your code correctly using code or highlight tags which are explained near the top of this link.

    Don't wait until the last minute (or 120 of them) to ask for help. Come here sooner, ask your instructor, the TAs, other students (as allowed), etc.

  4. #4
    Junior Member Rods's Avatar
    Join Date
    Sep 2014
    Location
    New York
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help ASAP (Submission is in two hours) :(

    I edited it to highlight. I got one day extension to submit. Can you guys help me now to solve this? I posted errors here.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,381
    Thanks
    53
    Thanked 2,397 Times in 2,350 Posts

    Default Re: Need help ASAP (Submission is in two hours) :(

    InputStream cannot be converted to long
    Read the API doc for the Random class's constructor to see what kind of arg it takes.
    cannot find symbol
    for(int i=0; i<dieToss.length; i++)
    ^
    symbol: variable length
    The compiler can not find a definition for the variable: length
    Where is it supposed to be defined?

    incomparable types: int[] and boolean
    The data types must be comparable. an int array can not be compared to a boolean variable

    The code has no comments so I don't know what each of those statements is supposed to do.

    --- Update ---

    The formatting of the posted code needs work.
    Nested statements should be indented.
    The ending } should be in the same column as the statement with the matching {.

    The messy code is hard to read because of the poor formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Need help ASAP (Submission is in two hours) :(

    Addressing the error messages:

    1. dieToss.java:6: error: incompatible types: InputStream cannot be converted to long

    What are you trying to do with this statement?
    Random rand = new Random( System.in );

    2. dieToss.java:8: error: cannot find symbol
    for(int i=0; i<dieToss.length; i++)

    dieToss.length would normally be used to determine the length of an array to iterate the array's elements. However, dieToss is the name of the class, not any array in the class. This error might be more obvious IF the class name began with a capital letter as it is supposed to in Java.

    3. dieToss.java:20: error: incomparable types: int[] and boolean
    if(value!=inRun)

    'value' is an int[] array and inRun is a boolean. The two can't be meaningfully compared. What did you mean to do with that statement?

    I recommend you take the pseudo-code you've been given and use that to comment your code.

Similar Threads

  1. weekly hours for each employee
    By sircamolate in forum Collections and Generics
    Replies: 18
    Last Post: September 1st, 2011, 06:09 PM
  2. Hours worked help
    By glacier23 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 10th, 2010, 11:58 PM
  3. need in few hours help me
    By erinbasim in forum Java Theory & Questions
    Replies: 3
    Last Post: February 2nd, 2010, 05:39 PM
  4. project needed in two hours
    By erinbasim in forum Project Collaboration
    Replies: 1
    Last Post: February 2nd, 2010, 03:21 AM