Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.6 kB
7
Indexable
Never
import java.util.Scanner;

public class EventPlanner {
    private static final int TABLE_SIZE_6 = 6;
    private static final int TABLE_SIZE_8 = 8;
    private static final int VENUE_CAPACITY = 56;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] groupSizes = new int[VENUE_CAPACITY / TABLE_SIZE_6];
        int groupCount = 0;

        while (true) {
            System.out.println("\nMenu:\n1. Enter the number of groups including the group size that are attending an event\n2. Create seating plan using first-fit-decreasing bin packing\n3. Exit");
            System.out.print("Enter your choice: ");
            int choice = scanner.nextInt();
            if (choice == 1) {
                System.out.print("Enter the number of groups: ");
                int numGroups = scanner.nextInt();
                for (int i = 0; i < numGroups; i++) {
                    System.out.print("Enter the size of group " + (i + 1) + ": ");
                    int groupSize = scanner.nextInt();
                    if (groupSize >= 2 && groupSize <= 6) {
                        groupSizes[groupCount++] = groupSize;
                    } else {
                        System.out.println("Group size must be between 2 and 6. Skipping invalid group size.");
                    }
                }
            } else if (choice == 2) {
                if (groupCount == 0) {
                    System.out.println("No group sizes entered.");
                } else {
                    int totalVacantSeats = VENUE_CAPACITY;
                    int table6Seats = 0;
                    int table8Seats = 0;
                    for (int i = 0; i < groupCount; i++) {
                        int groupSize = groupSizes[i];
                        if (groupSize >= TABLE_SIZE_8 && table8Seats < VENUE_CAPACITY / TABLE_SIZE_8) {
                            table8Seats += TABLE_SIZE_8;
                            totalVacantSeats -= TABLE_SIZE_8;
                        } else if (groupSize >= TABLE_SIZE_6 && table6Seats < VENUE_CAPACITY / TABLE_SIZE_6) {
                            table6Seats += TABLE_SIZE_6;
                            totalVacantSeats -= TABLE_SIZE_6;
                        }
                    }
                    System.out.println("\nSeating Plan:\nTable 6:");
                    for (int i = 0; i < table6Seats / TABLE_SIZE_6; i++) {
                        System.out.println("Group size: " + TABLE_SIZE_6);
                    }
                    System.out.println("Table 8:");
                    for (int i = 0; i < table8Seats / TABLE_SIZE_8; i++) {
                        System.out.println("Group size: " + TABLE_SIZE_8);
                    }
                    System.out.println("Total vacant seats: " + totalVacantSeats);
                }
            } else if (choice == 3) {
                System.out.println("Exiting...");
                break;
            } else {
                System.out.println("Invalid choice. Please try again.");
            }
        }
    }
}
*/    In this version, unnecessary variables have been removed, and the code has been compacted into a single while loop with concise logic.
    The enterGroupData and createSeatingPlan methods are no longer needed, and their functionality has been incorporated directly into the main method.
    The menu options, user input, and seating plan calculation are all handled within the while loop.

This version provides the same functionality as the previous versions while reducing the number of lines and maintaining readability.

/*