Created
December 30, 2018 18:22
-
-
Save irshu355/b3a2c57a8599439717ae3d4a9f4f907a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<Integer> 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<roomDistribution.size(); i++){ | |
lblRooms.get(i).setBackground(getResources().getDrawable(roomBgs[i])); | |
lblRooms.get(i).setText(""+roomDistribution.get(i)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment