19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

80 Chapter 2 Elementary <strong>Programming</strong><br />

Sections 2.17–2.18<br />

2.22 (Random character) Write a program that displays a random uppercase letter<br />

using the System.CurrentTimeMillis() method.<br />

2.23 (Find the character of an ASCII code) Write a program that receives an ASCII<br />

code (an integer between 0 and 127) and displays its character. For example, if the<br />

user enters 97, the program displays character a. Here is a sample run:<br />

Enter an ASCII code:<br />

The character is E<br />

69<br />

*2.24 (Financial application: monetary units) Rewrite Listing 2.10,<br />

ComputeChange.java, <strong>to</strong> fix the possible loss of accuracy when converting a<br />

double value <strong>to</strong> an int value. Enter the input as an integer whose last two digits<br />

represent the cents. For example, the input 1156 represents 11 dollars and 56 cents.<br />

*2.25 (Financial application: payroll) Write a program that reads the following information<br />

and prints a payroll statement:<br />

Employee’s name (e.g., Smith)<br />

Number of hours worked in a week (e.g., 10)<br />

Hourly pay rate (e.g., 6.75)<br />

Federal tax withholding rate (e.g., 20%)<br />

State tax withholding rate (e.g., 9%)<br />

Enter employee's name: Smith<br />

Enter number of hours worked in a week: 10<br />

Enter hourly pay rate: 6.75<br />

Enter federal tax withholding rate: 0.20<br />

Enter state tax withholding rate: 0.09<br />

Employee Name: Smith<br />

Hours Worked: 10.0<br />

Pay Rate: $6.75<br />

Gross Pay: $67.5<br />

Deductions:<br />

Federal Withholding (20.0%): $13.5<br />

State Withholding (9.0%): $6.07<br />

Total Deduction: $19.57<br />

Net Pay: $47.92<br />

Section 2.19<br />

*2.26 (Use input dialog) Rewrite Listing 2.10, ComputeChange.java, using input and<br />

output dialog boxes.<br />

*2.27 (Financial application: payroll) Rewrite Exercise 2.25 using GUI input and<br />

output dialog boxes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!