Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 12, 2019 14:48
Show Gist options
  • Save 0ryant/e1219044ad766ac07244ea5a96849c34 to your computer and use it in GitHub Desktop.
Save 0ryant/e1219044ad766ac07244ea5a96849c34 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - How many Buckets does Bob need?
public static int getBucketCount(double width, double height, double areaPerBucket, int extraBuckets) {
if ((width <= 0) || (height <= 0) || (areaPerBucket <= 0)||(extraBuckets<0)) {
return -1;
}
double wallArea = (width * height);
int bucketsNeeded = (int) ((wallArea / areaPerBucket) - extraBuckets);
if (bucketsNeeded < (wallArea/areaPerBucket)){
bucketsNeeded++;
}
return bucketsNeeded;
}
public static int getBucketCount(double width, double height, double areaPerBucket){
if ((width<0)||(height<0)||(areaPerBucket<0)){
return -1;
}
int bucketsNeeded = getBucketCount(width,height,areaPerBucket,0);
return bucketsNeeded;
}
public static int getBucketCount(double area,double areaPerBucket){
if ((area <0)||(areaPerBucket<0)){
return -1;
}
double sqRoot = Math.sqrt(area);
int bucketsNeeded = getBucketCount(sqRoot,sqRoot,areaPerBucket);
return bucketsNeeded;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment