#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Post Anybody knows how to solve this?? :D


    At the Popears restaurant, there are 3 tables available: Table A, Table B and Table C. For each table, there are only 2 seats available for customers. If the customer is not able to get his/her seat, he/she will need to rejoin the queue for another chance. You have been assigned to simulate this process by creating an application called SeatAllocationApp. Your program will do the following:
    a. Prompt the user to enter the names of 6 customers and add the names to a queue on a first-come-first-served basis. This will form the queue for the seat allocation process.
    b. Start the seat allocation process by dequeuing a customer and prompt him/her for his/her seat selection.
    c. On a successful match, your program will inform the customer that his/her allocation is successful.
    d. However, if his/her selected seat is not available, he/she will need to rejoin the queue.
    e. Your program will continue to do the seat allocation process (steps b to d) until all customers are successful seated.
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,023
    Rep Power
    1285
    I guess the question should be do you know how to solve it? What have you done?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by bullet
    I guess the question should be do you know how to solve it? What have you done?
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package seatallocationapp;
    import java.util.Scanner;
    
    /**
     *
     * @author Andrea
     */
    public class SeatAllocationApp {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logEic here
            Scanner sc = new Scanner(System.in);
            Queue q = new Queue(6);
            String a = null;
            String b = null;
            String c = null;
            int TA = 2;
            int TB = 2;
            int TC = 2;
            
            //Prompt the user to enter the names of 6 customers and add the names to a queue on a 
            //first-come-first-served basis. This will form the queue for the seat allocation process.
            int count = 0;
            String names = null;
            for(int i=1; i<7 ; i++)
            {
                System.out.print("Enter the name of customer #" + i + ": ");
                names = sc.nextLine();
                q.enqueue(names);
                
            }
            
            //Start the seat allocation process by dequeuing a customer and 
            //prompt him/her for his/her seat selection.
            
            for(int i =0; i<6; i++)
            {
                    System.out.println("Hi " + q.dequeue());
                    System.out.print("Please enter your choice of table: ");
                    String table = sc.nextLine();
                    
                    while(table.equals(a))
                    {
                        TA = count++;
                        System.out.print("Your selection is successful!");
                    }
            }
            
           
            
            
           
            
        }
    }
    this is what i came up with so far. but i cant seem to go any further.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    You need to work on the logic before trying to write any more code.
    Where are the counts of seats taken at each table kept?
    Is the choice of table a guessing game? If there are 6 seats and 6 customers, then they can all be seated as soon as they guess what table to sit at.

    In the current code the variable names need work. a,b,c are poor, non-descriptive names. Choose some names that say what the variables contain.

    Where is the definition for the Queue class.
    Last edited by NormR; December 19th, 2013 at 07:53 PM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Exclamation


    Thats why! I do not know how to get a count at each table or create each table.
    It is not a guessing game. Its like allocating a set to each person. if there is a seat from the table, dequeue the person. if there are no available seats then the person have to rejoin the queue and queue again.

    Sorry, i am a little poor at programming. how do i know what name to choose so that it states what the variable contains?? and how do i define a queue class???
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    how do i define a queue class?
    There are some classes in java that will perform as queues. Look at the API doc for the Queue interface and see what classes implement it.
    Start with "what the variable contains" and give it a name that describes that. A variable to holds the "number of seats at table 2" could be named: nbrSeatsTable2
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Exclamation


    Originally Posted by NormR
    There are some classes in java that will perform as queues. Look at the API doc for the Queue interface and see what classes implement it.
    Start with "what the variable contains" and give it a name that describes that. A variable to holds the "number of seats at table 2" could be named: nbrSeatsTable2
    What is an API doc??
  14. #8
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Here's a link to the API doc for java SE:http://docs.oracle.com/javase/7/docs/api/
    It has THE documentation for all the Java SE classes and their methods.

    Do you know how to create a class? A class for the Tables would be better than having several variables for each table.
    Last edited by NormR; December 20th, 2013 at 06:51 AM.

IMN logo majestic logo threadwatch logo seochat tools logo