Advertisement
Guest User

Reservation Example

a guest
Oct 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. public class Reservation {
  2.   int guestCount;
  3.   int restaurantCapacity;
  4.   boolean isRestaurantOpen;
  5.   boolean isConfirmed;
  6.  
  7.   public Reservation(int count, int capacity, boolean open) {
  8.     if (count < 1 || count > 8) {
  9.       System.out.println("Invalid reservation!");
  10.     }
  11.     guestCount = count;
  12.         restaurantCapacity = capacity;
  13.         isRestaurantOpen = open;
  14.   }  
  15.  
  16.   public void confirmReservation() {
  17.     if (restaurantCapacity >= guestCount && isRestaurantOpen) {
  18.       System.out.println("Reservation confirmed");
  19.       isConfirmed = true;
  20.     } else {
  21.       System.out.println("Reservation denied");
  22.             isConfirmed = false;
  23.     }
  24.   }
  25.  
  26.   public void informUser() {
  27.     // Write conditional here
  28.         if (!isConfirmed) {
  29.       System.out.println("Unable to confirm reservation, please contact resturant.");
  30.     } else {
  31.       System.out.println("Please enjoy your meal!");
  32.     }
  33.   }
  34.  
  35.   public static void main(String[] args) {
  36.     Reservation partyOfThree = new Reservation(3, 12, true);
  37.     Reservation partyOfFour = new Reservation(4, 3, true);
  38.     partyOfThree.confirmReservation();
  39.     partyOfThree.informUser();
  40.     partyOfFour.confirmReservation();
  41.     partyOfFour.informUser();
  42.   }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement