# Hw2_sol - The solutions for the homework 2 (posted on...

This preview shows pages 1–2. Sign up to view the full content.

The solutions for the homework 2 (posted on Blackboard) are: Liang textbook, page 64, problem 2.5. (Calculating tips) Write a program that reads the subtotal and the gratuity rate, and computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays \$1.5 as gratuity and \$11.5 as total. public class Exercise2_5 { public static void main(String args[]) { // Read subtotal java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter subtotal: "); double subtotal = input.nextDouble(); // Read subtotal System.out.print("Enter gratuity rate: "); double rate = input.nextDouble(); double gratuity = subtotal * rate / 100; double total = subtotal + gratuity; System.out.println("Gratuity is " + gratuity); System.out.println("Total is " + total); } } ---------------- Liang textbook, page 65, problem 2.11. (Payroll) Write a program that reads the following information and prints a payroll statement: Employee's name (e.g., Smith) Number of hours worked in a week (e.g., 10) Hourly pay rate (e.g., 6.75) [Page 65] Federal tax withholding rate (e.g., 20%) State tax withholding rate (e.g., 9%) Write this program in two versions: (a) Use dialog boxes to obtain input and display output; (b) Use console input and output. import javax.swing.JOptionPane; public class Exercise2_11a { public static void main(String args[]) { // Obtain input String name = JOptionPane.showInputDialog(null, "Enter employee's full name:", "Exercise2_12 Input", JOptionPane.QUESTION_MESSAGE); String hoursString = JOptionPane.showInputDialog(null, "Enter number of hours worked in a week:", "Exercise2_12 Input", JOptionPane.QUESTION_MESSAGE); double hours = Double.parseDouble(hoursString); String rateString = JOptionPane.showInputDialog(null, "Enter hourly pay rate:",

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/07/2011 for the course CSE 114 taught by Professor Tashbook during the Fall '08 term at SUNY Stony Brook.

### Page1 / 5

Hw2_sol - The solutions for the homework 2 (posted on...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online