This program asks the user to repeatedly enter floating-point numbers and reports the smallest whole number greater than or equal to the number, largest whole number less than or equal to the number, and absolute value of the number. It uses methods from the Math class like ceil(), floor(), and abs() to calculate these values. The program is provided with placeholders for the missing code and user input/output is displayed in comments for testing purposes.
Measures of Central Tendency: Mean, Median and Mode
Complete a program that asks the user to enter a floating-point numb.docx
1. Complete a program that asks the user to enter a floating-point
number (either positive or negative).
The program repeats while the user enters ‘y’ to continue.
The program allows a user to enter either a lowercase or
uppercase character.
Use the ceil use the ( ), floor ( ), and abs ( ) methods to
determine the smallest whole number that is greater than or
equal to the number entered, the largest whole number that is
less than or equal to the number entered, and the absolute value
of the number given, respectively. Use the
toLowercase ( )
method to change a given character value to lowercase if the
value is an uppercase value.
Supply the missing code and import the correct packages for the
predefined methods used.
Following is a copy of the screen results that might appear after
running your program, depending on the data entered after all
the changes have been made. The text entered by the user
appears in bold.
Enter a float number and I will tell you:
the smallest whole number > = to the number,
the largest whole number < = to the number,
and the absolute value of the number.
5.4
The smallest home number greater than 5.4 is 6.0
The larger whole number less than 5.4 is 5.0
The absolute value of 5.4 is 5.4
2. Do you want to enter more data?
y/n
y
Enter a float number and I will tell you:
the smallest home number > = to the number,
the largest whole number < = to the number, an
and the absolute value of the number.
-8.8
The smallest whole number greater than -8.8 is -8.0
The largest whole number less than -8.8 is -9.0
The absolute value of -8.8 is 8.8
Do you want to enter more data?
y/n
n
Complete the following Java program, inserting comments,
package names, or calls to methods of the class Math after the
bold comments. For readability, leave them blank lines and
comments in place throughout the program. Save program as
NumbersFixed.java
to the device or location specified by your instructor. Compile,
execute, and test program. After executing your program, select
and copy everything that appears on your screen. Paste the
copied text into a comment block at the end of your program.
// Include comments to identify the writer of the code
// and to describe the program.
import
java.util,*;
// The following statement imports the Math class.
3. import
public class NumbersFixed
{
static Scanner console = new Scanner (System.in);
public static void main (String[ ] args)
{
double x;
String token;
char again = ‘y’;
while
(again = = ‘y’)
{
System.out.println(“ Enter a float number and I will “
+ “tell you:n”
+ “the smallest whole number > = to the number,n”
4. + “the largest whole number < = to the number,n”
+ “and the absolute value of the number.n”);
x = console.nextDouble ( );
System.out.println(“nThe smallest whole number “
+ “greater than “
+
x
+
“ is
“
/ / Following is a method call to calculate the
/ / smallest whole number > = the input value.
+
+ “nThe largest whole number less than “
+
5. x
+” is “
/ / Following is a method call to calculate the
/ /largest whole number < = the input value.
+
+ “nThe absolute value of “
+
x
+
“ is “
/ / Following is a method call to calculate the
/ / absolute value of the input value.
+
+ “n” );
6. System.out.println( “Do you want to enter more data?”
+ “
y/n “);
token = console.next ( ) ;
again = token.charAt ( 0 ) ;
/ / The following statement converts the response
/ / character entered by the user to lowercase.
again =
}
}
}