APT: Pancakes

Class

public class Pancakes { public int minutesNeeded (int numCakes, int capacity) { // TODO: fill in code here } }

Problem Statement

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 numCakes 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, minutesNeeded, that returns the shortest time needed to cook numCakes pancakes in a pan that holds capacity pancakes at once. See the examples.

Constraints

Examples

  1. numCakes = 0
    capacity = 4
    
    Returns: 0
    
    
    It takes no time to cook 0 pancakes.

  2. numCakes = 2
    capacity = 2
    
    Returns: 10
    
    
    You cook both pancakes on one side for five minutes, then flip them over and cook each on the other side for another five minutes.

  3. numCakes = 3
    capacity = 2
    
    Returns: 15
    
    
    You cook pancakes 1 and 2 on one side for five minutes, then you take pancake 2 out of the pan, flip pancake 1 and start cooking pancake 3. After 10 minutes, pancake 1 is done so you take it out, pancake 3 can be flipped, and you can put pancake 2 back in the pan (since you removed the first pancake). Total time: 15 minutes.