private void calculateRoomsRequired(int adults, int children, int infants) { int counter = 0; if(adults + children + infants == 0) { showError("we need atleast a pax to proceed"); return; } if(adults + children + infants > MAX_HEADCOUNT) { showError("Booking exceeds maximum guests"); return; } if(adults + children > 7){ showError("Booking exceeds maximum adult + children"); return; } if(children > MAX_ROOMS_PER_BOOKKING * MAX_CHILDREN){ showError("Sorry, booking exceeds maximum children"); return; } if(infants > MAX_ROOMS_PER_BOOKKING * MAX_INFANTS){ showError("Sorry, booking exceeds maximum infants"); return; } if(infants + children > 1 && adults ==0){ showError("Sorry, we need atleast an adult for supervision"); return; } List roomDistribution = new ArrayList<>(); float roomsNeeded = children<=3 ? 1 : children/(float) MAX_CHILDREN; if(roomsNeeded % 1 != 0){ roomsNeeded++; } for(int i = 0; i < (int) roomsNeeded ; i++){ roomDistribution.add(0); } while (children > 0){ if(counter>=roomDistribution.size()){ counter=0; } roomDistribution.set(counter, roomDistribution.get(counter)+1); counter++; children--; } roomsNeeded = infants<=3 ? 1 : infants/(float) MAX_INFANTS; if(roomsNeeded % 1 != 0){ roomsNeeded++; } if(roomDistribution.size() < (int) roomsNeeded){ int diff = (int)roomsNeeded - roomDistribution.size(); for(int i = 0; i < diff ; i++){ roomDistribution.add(0); } } counter=0; while (infants > 0){ if(counter>=roomDistribution.size()){ counter=0; } roomDistribution.set(counter, roomDistribution.get(counter)+1); counter++; infants--; } if(roomDistribution.size() > adults){ showError("Sorry, we need more adults as we can't let the kids alone in rooms"); return; } if(roomDistribution.size() < MAX_ROOMS_PER_BOOKKING){ float adultPerRooms = adults/(float) MAX_ADULTS; if(adultPerRooms % 1 != 0){ adultPerRooms++; } int diff = (int) adultPerRooms - roomDistribution.size(); for(int i = 0; i< diff ;i++){ roomDistribution.add(0); } } counter = 0; while (adults>0){ if(counter>=roomDistribution.size()){ counter = 0; } roomDistribution.set(counter,roomDistribution.get(counter) + 1); adults--; counter++; } for(int i = 0; i