Created
August 12, 2019 14:48
-
-
Save 0ryant/e1219044ad766ac07244ea5a96849c34 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - How many Buckets does Bob need?
This file contains 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
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