Question: in java 6 . 7 What is the value of x after each of the following statements is executed? double x = Math.abs ( 7

in java
6.7 What is the value of x after each of the following statements is executed?
double x = Math.abs(7.5);
double x = Math.floor(7.5);
double x = Math.abs(0.0);
double x = Math.ceil(0.0);
double x = Math.abs(-6.4);
double x = Math.ceil(-6.4);
double x = Math.ceil(-Math.abs(-8+ Math.floor(-5.5)));
6.8(Parking Charges) A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write an application that calculates and displays the parking charges for each customer who parked in the garage yesterday. You should enter the hours parked for each customer. The program should display the charge for the current customer and should calculate and display the running total of yesterdays receipts. It should use the method calculateCharges to determine the charge for each customer.
6.9(Rounding Numbers) Math.floor can be used to round values to the nearest integere.g.,
double y = Math.floor(x +0.5);
will round the number x to the nearest integer and assign the result to y. Write an application that reads double values and uses the preceding statement to round each of the numbers to the nearest integer. For each number processed, display both the original number and the rounded number.
6.10(Rounding Numbers) To round numbers to specific decimal places, use a statement like
double y = Math.floor(x *10+0.5)/10;
which rounds x to the tenths position (i.e., the first position to the right of the decimal point), or
double y = Math.floor(x *100+0.5)/100;
which rounds x to the hundredths position (i.e., the second position to the right of the decimal point). Write an application that defines four methods for rounding a number x in various ways:
roundToInteger(number)
roundToTenths(number)
roundToHundredths(number)
roundToThousandths(number)
For each value read, your program should display the original value, the number rounded to the nearest integer, the number rounded to the nearest tenth, the number rounded to the nearest hundredth and the number rounded to the nearest thousandth.
6.11 Answer each of the following questions:
What does it mean to choose numbers at random?
Why is the nextInt method of class SecureRandom useful for simulating games of chance?
Why is it often necessary to scale or shift the values produced by a SecureRandom object?
Why is computerized simulation of real-world situations a useful technique?
6.12 Write statements that assign random integers to the variable n in the following ranges:
1<= n <=2.
1<= n <=100.
0<= n <=9.
1000<= n <=1112.
1<= n <=1.
3<= n <=11.
6.13 Write statements that will display a random number from each of the following sets:
2,4,6,8,10.
3,5,7,9,11.
6,10,14,18,22.
6.14(Exponentiation) Write a method integerPower(base, exponent) that returns the value of
base exponent
For example, integerPower(3,4) calculates 34(or 3*3*3*3). Assume that exponent is a positive, nonzero integer and that base is an integer. Use a for or while statement to control the calculation. Do not use any Math class methods. Incorporate this method into an application that reads integer values for base and exponent and performs the calculation with the integerPower method.
6.15(Hypotenuse Calculations) Define a method hypotenuse that calculates the hypotenuse of a right triangle when the lengths of the other two sides are given. The method should take two arguments of type double and return the hypotenuse as a double. Incorporate this method into an application that reads values for side1 and side2 and performs the calculation with the hypotenuse method. Use Math methods pow and sqrt to determine the length of the hypotenuse for each of the triangles in Fig. 6.14.[Note:Class Math also provides method hypot to perform this calculation.]
Fig.6.14
Values for the sides of triangles in Exercise 6.15.
Triangle Side 1 Side 2
13.04.0
25.012.0
38.015.0
6.16(Multiples) Write a method isMultiple that determines, for a pair of integers, whether the second integer is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise. [Hint: Use the remainder operator.] Incorporate this method into an application that inputs a series of pairs of integers (one pair at a time) and determines whether the second value in each pair is a multiple of the first.
6.17(Even or Odd) Write a method isEven that uses the remainder operator (%) to determine whether an integer is even. The method should take an integer argument and return true if the integer is even and false otherwise. Incorporate this method into an application that inputs a sequence

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!