In Java Sound power level is expressed in decibels. A decibel is 10 x log10(picoWatts), where a picoWatt is 10-12 Watts. To determine the acoustical power level produced by the combination of two sound sources, we do the following: 1. Convert each decibel level into picoWatts, using the formula, picoWatts = 10(decibels / 10) 2. Add the picoWatt powers. 3. Convert the sum back into decibels. Using good style, create a class called Decibels. In the main method, declare two component decibel values, dB1 and dB1, both double variables. Also declare a combined decibel value, combinedDB. Prompt for and input the two component decibel values. Then use the above formulas and Math’s pow method and Math’s log10 method to compute the combined sound power level. Enter first decibel level: 63 Enter second decibel level: 65 Combination decibel level = 67.1244260279434 dB import java.util.Scanner; public class Decibels { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); double dB1, dB2; double combinedDB; System.out.print("Enter first decibel level: "); dB1 = stdIn.nextDouble(); System.out.print("Enter second decibel level: "); dB2 = stdIn.nextDouble(); // your code System.out.println( "Combination decibel level = " + combinedDB + " dB"); } // end main } // end class Decibels
In Java
Sound power level is expressed in decibels. A decibel is 10 x log10(picoWatts),
where a picoWatt is 10-12 Watts. To determine the acoustical power level
produced by the combination of two sound sources, we do the following:
1. Convert each decibel level into picoWatts, using the formula, picoWatts =
10(decibels / 10)
2. Add the picoWatt powers.
3. Convert the sum back into decibels.
Using good style, create a class called Decibels. In the main method, declare two
component decibel values, dB1 and dB1, both double variables. Also declare a
combined decibel value, combinedDB. Prompt for and input the two component
decibel values. Then use the above formulas and Math’s pow method and Math’s
log10 method to compute the combined sound power level.
Enter first decibel level: 63
Enter second decibel level: 65
Combination decibel level = 67.1244260279434 dB
import java.util.Scanner;
public class Decibels
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
double dB1, dB2;
double combinedDB;
System.out.print("Enter first decibel level: ");
dB1 = stdIn.nextDouble();
System.out.print("Enter second decibel level: ");
dB2 = stdIn.nextDouble();
// your code
System.out.println(
"Combination decibel level = " + combinedDB + " dB");
} // end main
} // end class Decibels
Introduction
Scanner Class in Java: A class called Scanner may be found in java.util package and is used to get input of primitive types like int, double, etc., as well as strings. While it is the easiest technique for reading data in a Java program, it is not particularly effective if you require an input method for situations when time is a factor, such as in competitive programming.
The preset object System.in, which represents the standard input stream, is typically passed when creating an object of the Scanner class. If we wish to read input from a file, we can pass an object of the class File.
Step by step
Solved in 4 steps with 2 images