/* 
 * HayBales.java
 * July 2011
 * Solution for BHCSI programming contest question. Calculates diameter of
 * hay bale needed to make a bale weigh 1000 lbs. given the density of hay.
 *
 */

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
 *
 * @author cortneyriggs
 */
public class haybales {

    public static void main(String[] args) throws FileNotFoundException{

        //constants
        final double DENSITY_MIN = 6.0;
        final double DENSITY_MAX = 10.0;
        final int BALE_WIDTH = 5;
        final double BALE_TONAGE = 0.5;
        final double LBS_PER_TON = 2000;


        //varibles
        double density = 0.0;
        int maxHeight = 0;
        int numBalers = 0;
        long height = 0;
        Scanner input = new Scanner(new File("haybales.in"));

        //Get number of balers
        numBalers = input.nextInt();

        //loop through number of balers to calculate radius of bale
        for(int i = 0; i < numBalers; i++){

            //Get baler information
            density = input.nextDouble();
            maxHeight = input.nextInt();

            //check if density is in constraints
            if(density>DENSITY_MAX || density<DENSITY_MIN){
                System.out.println("Baler " + (i+1) + " density cannot produce a good alfalfa bale!");
            } 
            else {

                // calculate height to nearest inch starting from tons
                double V = BALE_TONAGE*LBS_PER_TON*(Math.pow(density, -1));
                height = Math.round(Math.sqrt((V)/(Math.PI*BALE_WIDTH))*12*2);
				
                //determine if within baler's capabilities
                if(height>maxHeight){
                    System.out.println("Baler " + (i+1) + " cannot make a bale tall enough for the density " + density + ".");
                } else {
                    System.out.println("Baler " + (i+1) + " will need to make a bale of height " + height + " inches.");
                    
                }
            }
        }
    }

}
