Computer Science Homework Solutions
Problem
#94421

Java programming

1. Modify the Payroll Program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked.

2. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. Once stop is entered as the employee name, the application should terminate. Make sure the program maintains all the functionality required in previous assignments and your source code is readable and well documented.

For right now, you just need to create a single instance of the class file and use the getters/setters to set and get the information.

I have attached the first part of this Payroll Project, just need to add the above to this program.

Attached file(s):
Attachments
BRAINMASS PAYROLL PROJECT.txt  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

BRAINMASS PAYROLL PROJECT.txt
Solution by: Abdun Mahmood, MSc, OTA ID#: 103644
Submitted on: August 30, 2006, 1:35 pm EDT
Computer Science, Data Structures and Algorithms
Year 2
java programming problem
--------------------------------------------------------------------------------

Solution

I have created the code and commented it so that you can understand how it is done.
Hope it helps. If you find it helpful, please leave comment and reserve future problems for me.
Thanks
OTA 103644

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

/**
* Created by
* User: OTA 103644
* Date: Aug 31, 2006
* Time: 12:40:00 AM
* To change this template use File | Settings | File Templates.
*/
public class payroll {
public static void main( String[] args){
InputStreamReader stdin = new InputStreamReader(System.in);
BufferedReader console = new BufferedReader(stdin);
String strEmpName,strHourlyRate;
double dblHourlyRate = 0; //initializing the variables
double dblWeeklyPay;
double dblHoursWorked = 0;
boolean loopAgain; //boolean flag to check if stop has been entered indicating end of outer loop
boolean error; //boolean flag to check if any of the numerical values are non-positive

//prompt and input
try{
do{
System.out.println("Please Enter the name of the Employee");
strEmpName = console.readLine();

// Check if the input name equals stop, ignoring case
if (strEmpName.equalsIgnoreCase("stop")){
break;
}
else loopAgain = true;

// Reading loop for Hourly Rate
error = true;
while (error){
error = false; //Setting this to false enables us to re-use the error variable
System.out.println("Please Enter the hourly rate");

strHourlyRate = console.readLine();
dblHourlyRate = Double.parseDouble(strHourlyRate);
if (dblHourlyRate<0){
System.out.println("Hourly Rate cannot be negative.");
error = true;
}
}

// Reading loop for Hours Worked
error = true;
while (error){
error = false; //Setting this to false enables us to re-use the error variable
System.out.println("Please Enter the working hours");
dblHoursWorked = Double.parseDouble(console.readLine());
if (dblHoursWorked<0){
System.out.println("Hours Worked cannot be negative.");
error = true;
}
}

// Calculate the Weekly Pay
dblWeeklyPay = dblHoursWorked * dblHourlyRate;
System.out.println("Employee: "+ strEmpName+ ", Weekly Pay: "+dblWeeklyPay);
}while (loopAgain); //End Do While
}
catch(IOException ioex)
{
System.out.println("Input error");
System.exit(1);
}

} //End Main
} //End payroll
Solution
What is this?
By OTA - Overall OTA Rating
Purchase Cost Now
$2.19 CAD (was ~$3.99)
Included in Download
  • Plain text response
  • Attached file(s):
    • Payroll.zip
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • The definition of a constructor. - What is a constructor?
  • Commenting on the enclosed Java Code - I need assistance in commenting on the enclosed code, consider things like code layout, use of variable names, general readability and understandability. The enclosed program suppose to Implement ...
  • 13365 Programming > C++ - I am attempting to complete Assignemt Exercise 13.12 in the Deitel&Deitel 5th edition version of C++ How to program. I am running into some early errors in trying to incorporate the Date class into ...
  • Java Programming - I'll give a start; this is the class definition; it has one member variable, one constructor method, and another public method: public class Car { private int no_doors; public Car(in ...
  • Java Code Example - I need assistance in commenting on the enclosed code, consider things like code layout, use of variable names, general readability and understandability. The enclosed program implements a class ca ...
Browse