Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . Table Reservation software in Java

Table Reservation software in Java

Here's an example of a table reservation software in Java for a restaurant:

```java
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

class Reservation {
    private LocalDate date;
    private LocalTime time;
    private int numberOfGuests;
    private String customerName;

    public Reservation(LocalDate date, LocalTime time, int numberOfGuests, String customerName) {
        this.date = date;
        this.time = time;
        this.numberOfGuests = numberOfGuests;
        this.customerName = customerName;
    }

    public LocalDate getDate() {
        return date;
    }

    public LocalTime getTime() {
        return time;
    }

    public int getNumberOfGuests() {
        return numberOfGuests;
    }

    public String getCustomerName() {
        return customerName;
    }
}

class ReservationSystem {
    private Map<LocalDate, Map<LocalTime, Reservation>> reservations;

    public ReservationSystem() {
        reservations = new HashMap<>();
    }

    public boolean makeReservation(LocalDate date, LocalTime time, int numberOfGuests, String customerName) {
        if (isReservationAvailable(date, time)) {
            Reservation reservation = new Reservation(date, time, numberOfGuests, customerName);

            if (!reservations.containsKey(date)) {
                reservations.put(date, new HashMap<>());
            }

            reservations.get(date).put(time, reservation);
            return true;
        }

        return false;
    }

    public boolean isReservationAvailable(LocalDate date, LocalTime time) {
        if (!reservations.containsKey(date)) {
            return true;
        }

        Map<LocalTime, Reservation> reservationsByTime = reservations.get(date);
        return !reservationsByTime.containsKey(time);
    }

    public Reservation getReservation(LocalDate date, LocalTime time) {
        if (reservations.containsKey(date)) {
            Map<LocalTime, Reservation> reservationsByTime = reservations.get(date);
            return reservationsByTime.get(time);
        }

        return null;
    }
}

public class Main {
    public static void main(String[] args) {
        ReservationSystem reservationSystem = new ReservationSystem();

        // Make a reservation
        LocalDate reservationDate = LocalDate.of(2023, 7, 5);
        LocalTime reservationTime = LocalTime.of(19, 30);
        int numberOfGuests = 4;
        String customerName = "John Doe";
        boolean isReservationMade = reservationSystem.makeReservation(reservationDate, reservationTime, numberOfGuests, customerName);

        if (isReservationMade) {
            System.out.println("Reservation made successfully!");
        } else {
            System.out.println("Reservation is not available at the specified date and time.");
        }

        // Check reservation details
        Reservation reservation = reservationSystem.getReservation(reservationDate, reservationTime);
        if (reservation != null) {
            System.out.println("Reservation details:");
            System.out.println("Date: " + reservation.getDate());
            System.out.println("Time: " + reservation.getTime());
            System.out.println("Number of guests: " + reservation.getNumberOfGuests());
            System.out.println("Customer name: " + reservation.getCustomerName());
        } else {
            System.out.println("No reservation found at the specified date and time.");
        }
    }
}
```

In this example, the `Reservation` class represents a reservation with properties such as date, time, number of guests, and customer name. The `ReservationSystem` class manages the reservations and provides methods for making a reservation, checking availability, and retrieving reservation details.

The `makeReservation` method checks if the specified date and time are available and creates a new `Reservation` object if they are. The `isReservationAvailable` method.

Post a Comment

1 Comments

Arvind Upadhyay said…
Table Reservation
•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.