CASE STUDY^137
//**
// This class provides an employee record object. The provided
// constructor takes the employee name as three strings and
// creates a Name field. It also takes the pay rate as a double
// value. It then inputs the hours for the week from System.in.
// Instance methods return the name formatted as a string and
// the pay for the employee. A class method returns the total pay.
// Constructor throws IOException.
//**
importjava.io.; // Package for IOException
importName; // Class for names
classEmployee
{
Name myName; // Employee name field
doublerate; // Pay rate
doublehours; // Hours worked
doublewages; // Simple wages (rate hours)
static doubletotal = 0.0; // Total pay for all employees
// Builds an employee record
publicEmployee (String first, String last, String middle,
doublepayrate) throwsIOException
{
BufferedReader in; // Input stream for strings
// Initialize fields
myName = newName(first, last, middle);
rate = payrate;
// Instantiate input stream in using System.in
in = newBufferedReader(newInputStreamReader(System.in));
// Prompt for hours worked
System.out.print("Enter hours worked by "+ myName.firstLast() + ": ");
// Get hours worked and convert from string to double
hours = Double.parseDouble(in.readLine());
wages = (double)((int)(hours * rate * 100.0+ 0.5))/100.0;
total = total + wages;
}
// Returns employee name
publicString name()
{
returnmyName.lastFirstMI();
}
// Returns employee wages
publicdouble pay()
{
returnwages;
}