Answer:
Code Listing 1.1 (Pay.java)
import java.util.Scanner; // Needed for the Scanner class
/**
This program calculates the user's gross pay.
*/
public class Pay
{
public static void main(String[] args)
{
// Create a Scanner object to read from the keyboard. Scanner keyboard = new Scanner(System.in);
// Identifier declarations
double hours; // Number of hours worked
double rate; // Hourly pay rate double pay; // Gross pay
// Display prompts and get input. System.out.print("How many hours did you work? "); hours = keyboard.nextDouble();
System.out.print("How much are you paid per hour? ");
rate = keyboard.nextDouble();
// Perform the calculations. if(hours <= 40)
pay = hours * rate;
else
pay = (hours - 40) * (1.5 * rate) + 40 * rate;
// Display results. System.out.println("You earned $" + pay);
}
}
Code Listing 1.2 (SalesTax.java)
import java.util.Scanner; // Needed for the Scanner class
/**
This program calculates the total price which includes
sales tax.
*/
public class SalesTax
{
public static void main(String[] args)
{
// Identifier declarations final double TAX_RATE = 0.055; double price;
double tax
double total; String item;
// Create a Scanner object to read from the keyboard. Scanner keyboard = new Scanner(System.in);
// Display prompts and get input. System.out.print("Item description: "); item = keyboard.nextLine(); System.out.print("Item price: $");
price = keyboard.nextDouble();
// Perform the calculations. tax = price + TAX_RATE;
totl = price * tax;
// Display the results. System.out.print(item + " $"); System.out.println(price); System.out.print("Tax $"); System.out.println(tax); System.out.print("Total $"); System.out.println(total);
}
}