/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

import java.time.* ;
import java.time.format.* ;
import java.time.temporal.* ;
import java.time.chrono.* ;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Ideone app = new Ideone() ;
		app.demo() ;
	}
	
	private void demo ( )
    {
        final Instant start = Instant.now().minus( Duration.ofMinutes( 21 ) );
        final Integer price = 10;   // This may come from some other place, such as a look-up in a database.
        Integer cost = this.calculateCostForElapsedTimeSoFar( start , price );
        System.out.println( "cost: " + cost );
    }
	
	public Integer calculateCostForElapsedTimeSoFar ( final Instant start , final Integer price )
    {
        // Determine elapsed time.
        Instant now = Instant.now();
        Duration elapsed = Duration.between( start , now );

        // See how many chunks of 15 minutes have occurred.
        Duration chunk = Duration.ofMinutes( 15 ); // Charge for every chunk of time in chunks of 15 minutes. You could make this a constant instead of a local variable.
        int chunks = Math.toIntExact( elapsed.dividedBy( chunk ) );   // Returns number of whole times a specified Duration occurs within this Duration.

        // Calculate charges.
        Integer cost = ( price * chunks );
        return cost;
    }
}