Professional Documents
Culture Documents
Code
Code
The parameter bigCount represents the count of big flour bags (5 kilos each).
The parameter smallCount represents the count of small flour bags (1 kilo each).
The parameter goal represents the goal amount of kilos of flour needed to
assemble a package.
Therefore, the sum of the kilos of bigCount and smallCount must be at least equal
to the value of goal. The method should return true if it is possible to make a
package with goal kilos of flour.
If the sum is greater than goal, ensure that only full bags are used towards the
goal amount. For example, if goal = 9, bigCount = 2, and smallCount = 0, the
method should return false since each big bag is 5 kilos and cannot be divided.
However, if goal = 9, bigCount = 1, and smallCount = 5, the method should return
true because of 1 full bigCount bag and 4 full smallCount bags equal goal, and
it's okay if there are additional bags left over.
EXAMPLE INPUT/OUTPUT:
* canPack (1, 0, 4); should return false since bigCount is 1 (big bag of 5 kilos)
and goal is 4 kilos.
* canPack (1, 0, 5); should return true since bigCount is 1 (big bag of 5 kilos)
and goal is 5 kilos.
* canPack (0, 5, 4); should return true since smallCount is 5 (small bags of 1
kilo)
and goal is 4 kilos, and we have 1 bag left which is ok as mentioned above.
* canPack (2, 2, 11); should return true since bigCount is 2 (big bags 5 kilos
each)
and smallCount is 2 (small bags of 1 kilo), makes in total 12 kilos and goal is 11
kilos.
NOTE: The method canPack should be defined as public static like we have
been doing so far in the course.
Write a method named getLargestPrime with one parameter of type int named number.
If the number is negative or does not have any prime numbers, the method should
return
-1 to indicate an invalid value.
The method should calculate the largest prime factor of a given number and return
it.
EXAMPLE INPUT/OUTPUT:
* getLargestPrime (0); should return -1 since 0 does not have any prime numbers
HINT: Since the numbers 0 and 1 are not considered prime numbers, they cannot
contain prime numbers.
Write a method named printSquareStar with one parameter of type int named number.
EXAMPLE INPUT/OUTPUT:
EXAMPLE 1
→ NOTE: For text in Code Blocks below, use code icon {...} on Udemy
*****
** **
* * *
** **
*****
Explanation:
***** 5 stars
** ** 2 stars space 2 stars
* * * 1 star space 1 star space 1 star
** ** 2 stars space 2 stars
***** 5 stars
EXAMPLE 2
********
** **
* * * *
* ** *
* ** *
* * * *
** **
********
HINT: To print on the same line, use the print method instead of println,
e.g. System.out.print(" "); prints a space and does not "move" to another line.
HINT: To "move" to another line, you can use an empty println call, e.g.
System.out.println(); .