ex 2 second option

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
1
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 EventAttendanceSTU123450 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        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];
        int totalTables = 0;
        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;
            }
        }
        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);
        scanner.close();
    }
}