/** SoundLevel.java computes the loudness of a sound at one distance,
 *   given its loudness at a different distance.
 * @author Joel Adams
 */

import java.util.Scanner;

public class SoundLevel {
  public static void main(String[] args) {
    System.out.println("To find the SPL of a sound at a distance:");
    Scanner kbd = new Scanner( System.in );
    // read loudness1, distance1, distance 2
    System.out.print("- what is the reference loudness (decibels)? ");
    int loudness1 = kbd.nextInt();
    System.out.print("- what is the reference distance (meters)? ");
    double distance1 = kbd.nextDouble();
    System.out.print("- what is the new distance? ");
    double distance2 = kbd.nextDouble();
    // compute loudness2
    long loudness2 =  loudness1 - Math.round(20*Math.log10(distance2/distance1));
    // display result
    System.out.println("\nThe SPL of the sound at distance "
    		           + distance2 + " is " + loudness2 + " db");
  }
}
