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

Thread: Cinema Seating arrangment

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

    Default Cinema Seating arrangment

    Hey, I'm wondering if anyone can help me, Im trying to create a simple cinema seating arrangement, where the x's are seats take and the o's are free. Problem is I cant seem to get the 0's to start where the X's finish. I'm new to java so what you see is the extent of my ability so far. Thanks for any help you can give at all!Here is what I haveso far;

    import java.util.Scanner;
     
    public class Exercise4iv
     
     
     
     
    {
     
    public static void main (String[] args)
     
    {
     
     
     
    int seats, taken, available, i, k;
     
     
    seats = 50;
    taken = 28;
    available = seats-taken;
    i=0;
    k=0;
    while( i<=taken){ 
    i++;
    System.out.print("\t X");
    if(i%8==0 )System.out.println();}
     
    while( k<=available){
    k++;
    System.out.print("\t O");
    if(k%8==0) System.out.println();}
    }}
    Here is what i want it to look like for example

    X X X X X X X X
    X X o o o o o o
    o o o o o o o o
    o o o o o o o o
    o o o o o o o o


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,132
    My Mood
    Mellow
    Thanks
    187
    Thanked 659 Times in 646 Posts

    Default Re: Cinema Seating arrangment

    Do you know or can you use arrays yet?

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Cinema Seating arrangment

    Use a single loop that iterates seats number of times. Inside have an if statement when counter reaches taken swap over to printing o's.
    Improving the world one idiot at a time!

  4. #4
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Cinema Seating arrangment

    If you know how to use arrays, then this problem becomes very, very simple.

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Cinema Seating arrangment

    Why do you need an array?
    What part of my simple algorithm above (which doesn't need an array) didn't you understand?
    Improving the world one idiot at a time!

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,132
    My Mood
    Mellow
    Thanks
    187
    Thanked 659 Times in 646 Posts

    Default Re: Cinema Seating arrangment

    No one said "need" before post #5, but it's important to understand what tools can be used in the design before wasting time guessing.

    Frankly, I think we care more than the OP.

  7. #7
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Cinema Seating arrangment

    Both you and aesguitar suggested using an array which is overkill for this. You would need two loops one to fill the array and one to print it. If you can work out the logic of how to fill the array with X's or O's then why not just print them to the screen instead of inserting them into an array?
    Improving the world one idiot at a time!

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,132
    My Mood
    Mellow
    Thanks
    187
    Thanked 659 Times in 646 Posts

    Default Re: Cinema Seating arrangment

    I'm not gonna argue an incomplete problem statement with you. In fact, I won't argue anything with you. Your idea is great, and everyone else's sucks.

    I asked my question, because I suspect that the status of the seats will change or will need to change as tickets are bought at which time simply printing patterns in bifurcated loops will be a difficult design to update with the current seating status. But I was thinking ahead, assuming facts not yet in evidence, and possibly wrong.

    --- Update ---

    I'm not gonna argue an incomplete problem statement with you. In fact, I won't argue anything with you. Your idea is great, and everyone else's sucks.

    I asked my question, because I suspect that the status of the seats will change or will need to change as tickets are bought at which time simply printing patterns in bifurcated loops will be a difficult design to update with the current seating status. But I was thinking ahead, assuming facts not yet in evidence, and possibly wrong.

  9. #9
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Cinema Seating arrangment

    Yes a better solution would be to use a 2D array and allow patrons to choose which seats instead on allocating them linearly.
    Improving the world one idiot at a time!

Similar Threads

  1. Replies: 6
    Last Post: November 25th, 2011, 02:58 PM