4 Replies - 10746 Views - Last Post: 22 July 2007 - 05:57 PM Rate Topic: -----

#1 twin2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-July 07

payroll program part 3

Post icon  Posted 22 July 2007 - 05:20 PM

hello all this is what I need to do if any body can help me i am using the eclipse program.

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. 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. this is what I have so far.
	/*
 
* Payroll3.java
 
*
 
* Created on July 4, 2007, 3:29 PM
 
*
 
* To change this template, choose Tools | Template Manager
 
* and open the template in the editor.
 
*/
 
 
 
/**
 
 
 
* 
 
 
* @author Nicholas Baatz 
 
 
*/ 
import java.util.Scanner; // program uses class Scanner 
 
 
public class Payroll3
{
 
 public Payroll3( String nameOfEmployee, float hourlyRate, float hoursWorked )// end constructor 
 
 {
 } 
 
 
 

 public static void main( String[] args) 
 {
  System.out.println( "Welcome to the Payroll Program! " );
 
  while (true)
  {
   // create scanner to obtain input from command window 
   Scanner input = new Scanner ( System.in );
   System.out.println(); // outputs a blank line 
   System.out.print( "Please enter the employee name or quit to terminate program: " );// prompt for and input employee name 
   String nameOfEmployee = input.nextLine(); 
 
   // read what user has inputted 
 
 
   if ( nameOfEmployee.equals("stop")) // Check whether user indicated to quit program 
   {
 


Is This A Good Question/Topic? 0
  • +

Replies To: payroll program part 3

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: payroll program part 3

Posted 22 July 2007 - 05:26 PM

this code is incomplete at best, there are } missing etc...

no one will do it for you, you will have to make an honest effort for real help.
Was This Post Helpful? 0
  • +
  • -

#3 twin2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-July 07

Re: payroll program part 3

Posted 22 July 2007 - 05:37 PM

View PostWilliam_Wilson, on 22 Jul, 2007 - 05:26 PM, said:

this code is incomplete at best, there are } missing etc...

no one will do it for you, you will have to make an honest effort for real help.

here i get to compile and run but it says it has errors
//* @author Nicholas Baatz 
 //Payroll Program Part 3
//Program calculates employee pay
// program uses class Scanner
 
import java.util.Scanner;  

public class Payroll
{
private static void Quit()
		{
		System.out.println("Goodbye");
	System.exit (0);
		}
	// main method begins execution of Java application
	public static void main(String args[])
		{
	   Employee emp = new Employee();
		// create Scanner to obtain input from command window
		Scanner input = new Scanner(System.in);
	if(emp.getName().equals("stop"))
			{
			System.out.println("stop entered, Thank you");
			Quit();
			} //end if
		   else
	
	System.out.print("Enter Employee Name : "); // prompt for name
				emp.setName(input.nextLine());   // get name
	if(emp.getName().equals("stop"))
			{
			System.out.println("stop entered, Thank you");
			Quit();
			} //end if
		   else
 
			System.out.print("Enter Employee payrate:$ "); // prompt
			emp.setpayRate(input.nextDouble());	// read first number from user
				if(emp.getpayRate() <= 0)
					{
						System.out.println("Invalid amount, Payrate must be positive");
						System.out.print("Please enter valid payrate:$ ");
						emp.setpayRate(input.nextDouble());
					} //end if
			System.out.print("Enter Employee hours: ");	// prompt
			emp.sethours(input.nextDouble());	// read second number from user
				if(emp.gethours() <= 0) 
					{
						System.out.println ("Invalid amount, Hours worked must be positive");
						System.out.print("Please enter actual hours worked: ");
						emp.sethours(input.nextDouble());
					} //end if 
	System.out.printf("\n%s's weekly gross pay will be $%.2f\n", emp.getName(), emp.getPay());
				Quit();
	}// end method main
} // end class Payroll
 
// Class Employee holds employee information
class Employee
 {  
   private String name;
   private double payRate;
   private double hours;
   //default constructor
	public Employee()
	{
		name = "";
		payRate = 0;
		hours = 0;
	}//end default constructor
  
	//Parameterized Constructor
	public Employee(String name, double payRate, double hours)
	{
		this.name = name;
		this.payRate = payRate;
		this.hours = hours;
	}//end constructor
	public void setName(String name) {
		this.name = name;
		}
	String getName()
	{
		return name;
	}
	public void setpayRate ( double payRate )
	{
		this.payRate = payRate;
	}
	public double getpayRate()
	{
		return payRate;
	}
	public void sethours ( double hours )
	{
		this.hours = hours;
	}
	public double gethours()
	{
		return hours;
	}
	public double getPay()
	{
		return (payRate * hours);
	}
}//end Class Employee


Was This Post Helpful? 0
  • +
  • -

#4 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1875
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: payroll program part 3

Posted 22 July 2007 - 05:38 PM

What are the errors?
Was This Post Helpful? 0
  • +
  • -

#5 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: payroll program part 3

Posted 22 July 2007 - 05:57 PM

you have no brackets {} around your else statement... personally i think it is the word else in your main method which should be removed, and all should be fine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1