208k views
4 votes
You're a short-order cook in a pancake restaurant, so you need to cook pancakes as fast as possible. You have one pan that can fit capacity pancakes at a time. Using this pan you must cook pamCakes pancakes. Each pancake must be cooked for five minutes on each side, and once a pancake starts cooking on a side it has to cook for five minutes on that side. However, you can take a pancake out of the pan when you're ready to flip it after five minutes and put it back in the pan later to cook it on the other side. Write the method, minutes Needed, that returns the shortest time needed to cook numCakes pancakes in a pan that holds capacity pancakes at once.

User Kasium
by
5.2k points

1 Answer

6 votes

Answer:

Step-by-step explanation:

The shortest time needed means that we are not taking into account the amount of time it takes to switch pancakes, flip them, or take them out of the pan, etc. Only cooking them. Therefore, written in Java would be the following...

public static int minutesNeeded (int numCakes, int panCapacity) {

int minutesNeededtoCook = 0;

while (numCakes != 0) {

if (numCakes > panCapacity) {

numCakes -= panCapacity;

minutesNeededtoCook += 10;

} else {

numCakes = 0;

minutesNeededtoCook += 10;

}

}

return minutesNeededtoCook;

}

The code takes in the amount of pancakes and the pan capacity, then compares them and adds 10 minutes (5 on each side) per pancake batch that is being made until all the pancakes are made.

User Chris Ladd
by
4.9k points