Untitled
unknown
plain_text
2 years ago
2.4 kB
10
Indexable
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome! How many people will be attending today?");
Scanner sc = new Scanner(System.in);
int totalNr = sc.nextInt();
int grSizeTotal = 0;
int groupsNr, size;
if(totalNr > 1 && totalNr <= 56) {
System.out.println("Awesome! How many groups are there?");
groupsNr = sc.nextInt();
System.out.println("Amazing! Could you tell us how many groups will there be for each size?");
int[] arr_groups = new int[5];;
if(grSizeTotal <= groupsNr) {
for(int i = 2; i <= 6; ++i){
System.out.println("Group size " + i + " :");
size = sc.nextInt();
grSizeTotal += size;
arr_groups[i - 2] = size;
}
System.out.println("All done. There will be a total of " + totalNr + " people, with " + groupsNr + " groups and for each group, there will be: ");
for(int i = 2; i<= 6; ++i) {
System.out.println("Group " + i + ": " + arr_groups[i - 2]);
}
int tables6Count = 0;
int emptySpaces = 0;
int seatsLeft = 6;
for (int i = 6; i >= 2; --i) {
int current_size = arr_groups[i-2];
int group_size = i;
for (int j = current_size; j > 0; --j) {
if (seatsLeft >= group_size){
seatsLeft -= group_size;
} else {
++tables6Count;
emptySpaces += seatsLeft;
seatsLeft = 6;
seatsLeft -= group_size;
}
}
}
System.out.println("There will be " + tables6Count + " tables which will have the capacity for 6 people. The total vacant seats are " + emptySpaces);
} else {
System.out.println("Can you make sure you entered the correct groups number please?");
}
} else {
System.out.println("We are sorry, we don't have this availability. Please try again.");
}
}
}Editor is loading...