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 13 of 13

Thread: Help with Assignment

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with Assignment

    Hi folks. I am currently studying Computer Science and one of the modules I am taking at the moment is Concurrent & Distributed Systems. My first assignment involves using await statements and semaphores for a train track using Eclipse. I have wrote out code but it has many errors. The link below shows the assignment question and below that is the code I have written so far. Can anyone assist me in completing this assignment? I would be very grateful

    https://docs.google.com/viewer?a=v&q...yDbwCEKc0Z8IcA

    Code
    Global Invariant: (NumberOfTrainsInAnySection <= 1) AND (TotalTrainsOnTrack <= 8)
    Process main {
    	/* Declare and initialize global variables */
    Const Number_Of_Trains = 10;
    Int NumberOnTrack =0;
     
    /* sections on the traintrack */
    string  sections[0..10]  =  {“[.....]”, “[.....]”, “[.....]”, “[.....]”, “[.....]”, “[.....]”, “[.....]”, “[.....]”,“[.....]”, “[.....]”, “[.....]”, “[.....]”, };
     
    //* Set the train moving 
    	 for (count= 1 to NUMBER_OF_TRAINS){
    		int entry= {0...0}; 
                       	int exit = { 0...11 }; 
                       	TrainProcess (entry,  exit);
                   } /* end  for *
    } /* end main process
     
    // Train Process
    process TrainProcess (int s, int t) {
     /* Wait if track is too crowded
    <await (numberOnTrack<=8) numberOnTrack++; >
        /* wait for section 1 to be clear from the right side
         <await ( (section[1]==”[.....]”) section[1]=”[“+entry+”-->”+exit”]”;>
        /* move forward to exit position (which is 10s) */
        int currentPosition = 0*s;
        int nextPosition = 0*s+1;
        do   {
           <await (sections[nextPosition]==”[.....]”)  sections[nextPosition]=sections[currentPosition]; 
                              sections[currentPosition]=”[.....]”; >
           currentPosition = nextPosition;
           nextPosition = (nextPosition+1) SECTIONS 8;
        } while (currentPosition <> 2*t)
       /* move off the track*/
       < slots[currentPosition]=”[.....]”; numberOnTrack-->
    } /* end TrainProcess


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with Assignment

    Can you explain what problems you are having?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Assignment

    Well the main process is for the trains to travel safely on the track and an await statement is required for the trains to cross over the junction safely. I think that I have declared the improper global variables and my await statements in the Train Process section is wrong also. Could anyone help me to correct it?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with Assignment

    Do you have a java program you are working on? The posted code is not valid java code.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Assignment

    I have written this code in Eclipse. Because I'm not that good at Java (or programming in general) the code is probably mixed up.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with Assignment

    Quote Originally Posted by docguy89 View Post
    I have written this code in Eclipse. Because I'm not that good at Java (or programming in general) the code is probably mixed up.
    You have completely invalid syntax in there, which makes it very hard to determine exactly what you're asking. I recommend fixing the syntax and compiler errors and creating an SSCCE that demonstrates the smallest piece of the program you're working on.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help with Assignment

    Yep, your first step will be to learn basic Java syntax which you can do at the Java tutorials that are linked to in Kevin's "useful links" signature links above, or which you can find here. You can't guess at this stuff and pray that it might work, and we'll not be able to help you til you've taught yourself at least some of the rudiments of the language. Also contact your instructor to schedule some intense one-on-one counseling as you have a lot of catching up to do, it appears.

  8. #8
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Assignment

    The assignment has to be in for today and I still cannot get it working

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with Assignment

    an await statement is required
    There is no await statement in java.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Assignment

    Quote Originally Posted by Norm View Post
    There is no await statement in java.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with Assignment

    Recode the project in java.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Assignment

    Yes I understand. The code listed in my first post is the algorithm, all I have to do now is implement it using Eclipse. Can any of you guys help me to implement it?

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with Assignment

    What have you got for a design for the program?
    Do you have any java code written for some of the steps in your design?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Assignment
    By marty_ in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 7th, 2012, 04:26 PM
  2. Really need help on assignment
    By coorscollector in forum Java Theory & Questions
    Replies: 2
    Last Post: January 16th, 2012, 06:08 PM
  3. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  4. Help with assignment
    By NPVinny in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 3rd, 2010, 05:31 PM
  5. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM