Question

In: Computer Science

JAVA: Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7...

JAVA: Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7 p.m., or 9 p.m. Design a JAVA program that accepts reservations for specific tables at specific times; the user enters the number of customers, the table number, and the time. Do not allow more than four guests per table or invalid table numbers or times. If an attempt is made to reserve a table already taken, re-prompt the user. Continue to accept reservations until the user enters a sentinel value or all slots are filled. Then display all empty tables in each time slot.

The answer should be a JAVA program this is the second time I'm asking this question because the first answer was written in python. A java program is needed, written in the Java programming language.

Solutions

Expert Solution

Here is the Java code:

import java.util.Scanner;

public class Main
{
        public static void main(String[] args) {
            int[][] guests = new int[3][20];
            String[] timesToShow = {"5 pm.", "7 pm.", "9 pm."};

            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 20; j++)
                    guests [i][j] = 0;         // All unbooked initially
           int maxReservations = 60, curntReservations = 0;
           
            Scanner sc = new Scanner (System.in);
                    
            do {
                System.out.println(" Le Chef Heureux Restaurant Reservations");
                System.out.println(" ---------------------------------------");
                System.out.print (" Please enter R to make a reservation, any other key to quit: ");
                String s = sc.nextLine ().trim().toLowerCase ();
                if (!s.equals("r")) break;
                System.out.print (" Please enter time for reservation (5/7/9): ");
                int tim = sc.nextInt();
                System.out.print (" Please enter table number 1-20: ");
                int tabl = sc.nextInt();
                System.out.print (" Please enter number of guests 1-4: ");
                int g = sc.nextInt();
                sc.nextLine ();   // clear up input buffer
                if ((tim != 5) && (tim != 7) && (tim != 9)) {
                    System.out.println (" Invalid time entered, please retry.");
                    continue;
                }
                if ((tabl < 1) || (tabl > 20)) {
                    System.out.println (" Invalid table entered, please retry.");
                    continue;
                }
                if ((g < 1) || (g > 4)) {
                    System.out.println (" Invalid guests entered, please retry.");
                    continue;
                }
                int i = (tim == 5? 0 : (tim == 7? 1 : 2));
                
                if (guests [i][tabl-1] == 0) {
                    guests [i][tabl-1] = g;
                    System.out.println (" Table booked.");
                    curntReservations++;
                }
            else {
                    System.out.println (" Table already reserved by somebody else, please try again.");
            }           
            } while (curntReservations < maxReservations);
            
            for (int i = 0; i < 3; i++) {
                    System.out.println (" Empty tables at " + timesToShow[i] + " (if any) ");
                for (int j = 0; j < 20; j++) {
                    if (guests[i][j] == 0) 
                        System.out.print (j+1);
                    System.out.print (" ");
                }
                System.out.println ();
            }
            
            
        }
}

Related Solutions

Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7 p.m.,...
Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7 p.m., or 9 p.m. Design a program that accepts reservations for specific tables at specific times; the user enters the number of customers, the table number, and the time. Do not allow more than four guests per table or invalid table numbers or times. If an attempt is made to reserve a table already taken, reprompt the user. Continue to accept reservations until the user...
DESIGN IN RAPTOR PROGRAMMING APP Le Chef Heureux Restaurant has 20 tables that can be reserved...
DESIGN IN RAPTOR PROGRAMMING APP Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7 p.m., or 9 p.m. Design a program that accepts reservations for specific tables at specific times; the user enters the number of customers, the table number, and the time. Do not allow more than four guests per table or invalid table numbers or times. If an attempt is made to reserve a table already taken, reprompt the user. Continue to...
restaurant has 5 tables available. People arrive at times of a Poisson process with rate of...
restaurant has 5 tables available. People arrive at times of a Poisson process with rate of 6 per hour. The amount of time for a person to eat has an exponential distribution with a mean of 30 minutes. People who arrive when all 5 tables are full turn around and leave without eating at the restaurant. In the long run, what fraction of time is the restaurant full?
The patio of a restaurant has three tables at which two, four, and five patrons can...
The patio of a restaurant has three tables at which two, four, and five patrons can be seated, respectively. A party of eleven is to be seated on the patio. (a) In how many ways can the party of eleven be seated at the three tables (it is not important in which seats at each table the patrons sit). (b) Three friends among the party wish to sit together. In how many ways can the party of eleven be seated...
Restaurant Pricing. Consider a restaurant that charges $10 for all, you can eat and has 20...
Restaurant Pricing. Consider a restaurant that charges $10 for all, you can eat and has 20 customers at this price. The slope of the demand curve is minus−​$0.20 per​ meal and the marginal cost of providing a meal is ​$66. ​1.) Use the line drawing tool to draw and label the demand line. ​2.) Use the line drawing tool to draw and label the marginal revenue line. ​3.) Use the line drawing tool to draw the marginal cost line. Carefully...
Gina has been head chef at a local Italian restaurant for the last 15 years. She...
Gina has been head chef at a local Italian restaurant for the last 15 years. She is from a large Italian family that loves not only cooking but also eating. Although Gina has grown up around large amounts of food and hearty appetites, she has learned to control her weight and eat moderately. However, Gina's husband, Anthony, has difficulty moderating his eating habits. They have been married for three years, and in that time Anthony has put on 20 kg,...
The owner of an exclusive restaurant has two tables but only one waiter. If the second...
The owner of an exclusive restaurant has two tables but only one waiter. If the second table is occupied, the owner waits on that table himself. Service times are exponentially distributed with mean 1 hour, and the time between arrivals is exponentially distributed with mean 1.5 hours. When the restaurant is full, people must wait outside in line. a) What percentage of the time is the owner waiting on a table? b) If the owner wants to spend at most...
Business Law Question Alina, a chef who has never owned her own restaurant, sues a builder...
Business Law Question Alina, a chef who has never owned her own restaurant, sues a builder who failed to finish building her first restaurant on time. She presents evidence of the profits made by similar restaurants that have been in business for some time. Is this good evidence of the damages she has suffered because of the delay? To what damages is she entitled?
Task 7 - Memory (5 +5 + 5 +5 = 20 marks) Please explain in your...
Task 7 - Memory (5 +5 + 5 +5 = 20 marks) Please explain in your own words for each part of Question 7. Quote your references in your ―References‖ / ―Bibliography‖ (a) What does INTEL‘s ―Optane Memory‖ provide? (b) What are some of the claims made by the ―Intel Marketing Department regarding Optane Memory. DDR5 memory is the latest computer memory being developed and will eventually replace DDR4 memory. (c) What are the maximum clocks speeds for DDR4 memory,...
1. Create an ERD that has at least 5 tables in it and include all of...
1. Create an ERD that has at least 5 tables in it and include all of the details and the correct notation (Min/Max cardinality and relationship name.) 2. Write a paragraph that explains the ERD. 3. Write the SQL Create, Insert, and Update statement to insert one of the entities from this ERD into a database.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT