FLOUR PACK PROBLEM

 Write a method called canPack with three parameters of type int named bingCount, smallCount, goal.
The parameter bigCount represents the count of a big bag of flour bags(5Kg) each.
The parameter smallCount represents the count of a small bag of flour bags(1Kg) each.
The parameter goal represents the goal amount of kilos of flour needed to assemble a package.
therefore the sum of kilos bigCount and smallCount must be equal to the value of the goal. the method should true if it is possible to make a package with goal kilos of flour.
If the sum is greater than the goal, ensure that only full bangs are used toward the goal amount.
if any negative parameter is used return negative.
package com.cnc;

public class Main {

public static void main(String[] args) {
System.out.println(canPack(2,0,6));
System.out.println(canPack(1,0,5));
}
public static boolean canPack(int bigCount, int smallCount, int goal){
if (bigCount * 5 + smallCount >= goal){

for (int i = 0; i <= bigCount; i++){
for (int j = 0; j <= smallCount; j++){
if (i * 5 + j == goal){
return true;
}
}
}

}

return false;
}
} 

Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

USER INPUT PRINT ORIGINAL,REVERSE ARRAY AND SORTED ARRAY