Chapter 6 (Web site development) Methods 305 EXERCISES 6.7 What is
Chapter 6 Methods 305 EXERCISES 6.7 What is the value of x after each of the following statements is performed? a) x = Math.abs( 7.5 ); b) x = Math.floor( 7.5 ); c) x = Math.abs( 0.0 ); d) x = Math.ceil( 0.0 ); e) x = Math.abs( -6.4 ); f) x = Math.ceil( -6.4 ); g) x = Math.ceil( -Math.abs( -8 + Math.floor( -5.5 ) ) ); 6.8 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 applet that calculates and displays the parking charges for each customer who parked a car in this garage yesterday. You should enter in a JTextField 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 yesterday s receipts. The program should use the method calculateChargesto determine the charge for each customer. 6.9 An application of method Math.flooris rounding a value to the nearest integer. The statement y = Math.floor( x + .5 ); will round the number x to the nearest integer and assign the result to y. Write an applet 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 Math.floor may be used to round a number to a specific decimal place. The statement y = Math.floor( x * 10 + .5 ) / 10; rounds x to the tenths position (i.e., the first position to the right of the decimal point). The statement y = Math.floor( x * 100 + .5 ) / 100; rounds x to the hundredths position (i.e., the second position to the right of the decimal point). Write an applet that defines four methods to round a number x in various ways: a) roundToInteger( number ) b) roundToTenths( number ) c) roundToHundredths( number ) d) 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. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01