CS 630 - Computing Fundamentals I - Fall 2005
Homework 2


Loyola College > Department of Computer Science > CS 630 > Homework > Homework 2

Due

Monday, September 26th at the beginning of class

Problems

Exercises (pp. 54-55)
2.4
2.6
2.7f,j,l,n

Programming Projects (p. 109)
2.5

Additional Problem (myCodeMate 2.16)
Write a program that prompts the user to enter the number of hours they worked, the pay rate per hour, and the percentage they are taxed. Then print the number of hours the student worked, their gross earnings, and their net earnings.
You may complete the following code:

//********************************************************************************************
//
// WageCalculator.java
//
// This program prompts the user to input the number of hours worked, the pay rate, and the
// tax rate, and prints the number of hours worked, the gross earnings, and the net earnings.
//********************************************************************************************
import java.util.Scanner;
import java.text.NumberFormat;

public class WageCalculator {
     //
     // Computes gross earning and net earnings from number of hours worked, pay rate and tax rate.
     //
     public static void main(String[] args) {
          int hours = 0;
          double payRate = 0, taxRate = 0;
          double netEarnings, grossEarnings;

          String hourMessage = "Enter the number of hours worked: ";
          String payMessage = "Enter the pay rate per hour: ";
          String taxMessage = "Enter the tax rate as a percentage: ";

          Scanner scan = new Scanner(System.in);

          // --------------------------------
          // ----- ENTER YOUR CODE HERE -----
          // --------------------------------


          // --------------------------------
          // --------- END USER CODE --------
          // --------------------------------


          NumberFormat fmt = NumberFormat.getCurrencyInstance();
          System.out.println("Hours worked: " + hours);
          System.out.println("Gross earnings: " + fmt.format(grossEarnings));
          System.out.println("Net earnings: " + fmt.format(netEarnings));

     } //method main
} //class WageCalculator