Untitled

ex 3
mail@pastecode.io avatar
unknown
plain_text
a year ago
3.6 kB
4
Indexable
Never
import java.util.Scanner;
//Part of this code is created based in the information provided by the lecturer. I use IntelliJ IDEA instead of Visual Code.
public class EventAttendanceSTU123450TEST1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean exit = false;
        while (!exit) {
            System.out.println("\nMenu:");
            System.out.println("1. Enter the number of groups including the group size that are attending an event");
            System.out.println("2. Create seating plan");
            System.out.println("3. Exit");
            System.out.print("Enter your choice: ");
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    enterGroupSizes(scanner);
                    break;
                case 2:
                    createSeatingPlan(scanner);
                    break;
                case 3:
                    exit = true;
                    break;
                default:
                    System.out.println("Invalid option. Please select a correct option.");
            }
        }
        scanner.close();
    }
    private static void enterGroupSizes(Scanner scanner) {
        System.out.print("Enter the total number of people attending the event: ");
        int totalAttendees = scanner.nextInt();
        System.out.print("Enter the number of groups: ");
        int numGroups = scanner.nextInt();
        int[] groupSizes = new int[numGroups];
        for (int i = 0; i < numGroups; i++) {
            System.out.print("Enter the size of group " + (i + 1) + ": ");
            groupSizes[i] = scanner.nextInt();
        }
        System.out.println("Total Attendees: " + totalAttendees);
        System.out.println("Number of Groups: " + numGroups);
        System.out.println("Group sizes:");
        for (int i = 0; i < numGroups; i++) {
            System.out.println("Group " + (i + 1) + ": " + groupSizes[i]);
        }
    }
    private static void createSeatingPlan(Scanner scanner) {
        System.out.print("Enter the total number of people attending the event: ");
        int totalAttendees = scanner.nextInt();
        System.out.print("Enter the number of groups: ");
        int numGroups = scanner.nextInt();
        int[] groupSizes = new int[numGroups];
        for (int i = 0; i < numGroups; i++) {
            System.out.print("Enter the size of group " + (i + 1) + ": ");
            groupSizes[i] = scanner.nextInt();
        }
        int numTables6 = 0;
        int numTables8 = 0;
        for (int groupSize : groupSizes) {
            if (groupSize <= 6) {
                numTables6++;
            } else if (groupSize <= 8) {
                numTables8++;
            } else {
                int numTables6Needed = groupSize / 6;
                int remainder = groupSize % 6;
                if (remainder != 0) {
                    numTables6Needed++;
                }
                numTables6 += numTables6Needed;
            }
        }
        int totalTables = numTables6 + numTables8;
        System.out.println("Total Attendees: " + totalAttendees);
        System.out.println("Number of Groups: " + numGroups);
        System.out.println("Group sizes:");
        for (int i = 0; i < numGroups; i++) {
            System.out.println("Group " + (i + 1) + ": " + groupSizes[i]);
        }
        System.out.println("Number of Tables (6-person): " + numTables6);
        System.out.println("Number of Tables (8-person): " + numTables8);
        System.out.println("Total Number of Tables: " + totalTables);
    }
}