Results 1 to 12 of 12
  1. #1
    cloudent01 is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Payroll Program 3 question

    I have been beeting my head aginst a wall
    i have to come up with a payroll program
    that produces
    Input name: Tim
    input time : 40 hours
    input rate: $23
    Produce: Tim made (sum of time * rate) $920
    Input name: Tim
    input time : 40 hours
    input rate: $23
    Produce: Tim made ((sum of time * rate)+previous answer) $1840

    but i cannot get it to add in the previous answer

    Java Code:
    import java.util.Scanner;
    class Week4PR
    {
    		public static void main(String[] args) {
    
    			Scanner input = new Scanner(System.in);
    			System.out.println("The program determines the employees weekly pay.");
    			System.out.println("Please enter the requested information, Thanks!");
    			
    		do{
    			System.out.print( "Please enter the employees name or stop to quit:" );
    			String PersonName = input.next();
    			if(PersonName.compareTo("stop") == 0)
    	        {
    	            System.out.println();
    	            System.out.println("*** Thank You for choosing this program, Good Bye! ***");
    	            System.out.println();
    	            break;
    	        }
    	       double Hours;
    	       double Rate;
    	       double sum;
    
    	       System.out.print( "Enter hours worked this week: " ); 
    	       Hours = input.nextDouble();
    	       while (Hours < 0)
    			{
    				System.out.print("Enter a positive number of hours worked:");
    				Hours = input.nextDouble();}
    
    	       System.out.print( "Enter your hourly pay rate: " ); 
    	       Rate= input.nextDouble();
    	       while (Rate < 0) 
    			{
    				System.out.print("Enter a positive number for pay rate:");
    				Rate = input.nextDouble(); }
    	       
    	       System.out.printf( "Payroll for %s\n",PersonName );
    
                    sum = Hours * Rate;
                    System.out.printf( "Weekly pay is %.2f", sum );
                    System.out.println();
                    } while(true);
    		} 
    	}
    class Employee
    {
    	private String name;
    	private double Rate;
    	private double Hours;
            public Employee ()
    	{
    		name = "";
    		Rate = 0.0;
    		Hours = 0.0;
    	}
    	public Employee(String employeenameIn, double hourlyRateInDollarsIn, double hoursWorkedInWeekIn) {
    		name = employeenameIn;
    		Rate = hourlyRateInDollarsIn;
    		Hours = hoursWorkedInWeekIn;
    	}
    	public void setName (String name) {
    		this.name = name;
    	}
    	public String getName () {
    		return name;
    	}
    	public void setpayRate (double payRate) {
    		this.Rate = payRate;
    	}
    	public double getpayRate () {
    		return Rate;
    	}
    	public void sethoursWorked (double hoursWorked) {
    		this.Hours = hoursWorked;
    	}
    	public double gethoursWorked () {
    		return Hours;
    	}
    	public double getearnedPay () {
    		return Rate * Hours;
    	}
    } // end class Employee
    I know that i need to add something but i do not know what, any help would be greatly appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Payroll Program 3 question

    Can you add comments to the program's output showing what is wrong with it and what the output should be?

  3. #3
    cloudent01 is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Payroll Program 3 question

    Here is the current output:

    The program determines the employees weekly pay.
    Please enter the requested information, Thanks!
    Please enter the employees name or stop to quit:tim
    Enter hours worked this week: 40
    Enter your hourly pay rate: 23
    Payroll for tim
    Weekly pay is 920.00
    Please enter the employees name or stop to quit:tim
    Enter hours worked this week: 40
    Enter your hourly pay rate: 23
    Payroll for tim
    Weekly pay is 920.00
    Please enter the employees name or stop to quit:

    I need the output to add previous entries

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Payroll Program 3 question

    I need the output to add previous entries
    Please edit the output and show what you want the output to look like. I have no idea how and where you want the extra data displayed.

  5. #5
    cloudent01 is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Payroll Program 3 question

    Oops sorry i seem to be still beeting my head aginst the wall


    The program determines the employees weekly pay.
    Please enter the requested information, Thanks!
    Please enter the employees name or stop to quit:tim
    Enter hours worked this week: 40
    Enter your hourly pay rate: 23
    Payroll for tim
    Weekly pay is 920.00
    Please enter the employees name or stop to quit:tim
    Enter hours worked this week: 40
    Enter your hourly pay rate: 23
    Payroll for tim
    Weekly pay is 920.00
    Total for Pay tim is $1840
    Please enter the employees name or stop to quit:tim
    Enter hours worked this week: 40
    Enter your hourly pay rate: 23
    Payroll for tim
    Weekly pay is 920.00
    Total for Pay tim is $2760
    Please enter the employees name or stop to quit:

    i want the application to add all the previous weeks and (be able to swich between employees, such as tim, mary..... and add to each accordinly this part may not be necesssary but would be helpful if possible with my current code)

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Payroll Program 3 question

    Total for Pay tim is $1840
    Is this the line you want added to the program?
    The way you add together a list of numbers is to use a variable to accumulate the total in. Initialize it to 0 and then add to it the next value as you get it.
    int var = 0;
    begin the loop
    compute a value
    var = var + value <<< add the new value to the accumulation
    // var now has the sum of all the previous values
    end loop

  7. #7
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default Re: Payroll Program 3 question

    Well you have an employee class on the bottom there, but you never use it. I can already see how using that Class can help you store information about the employee's payment history :) Think hard. If you really have no idea then come back to us, and I'll be happy to nudge you in the right direction :)

  8. #8
    cloudent01 is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Payroll Program 3 question

    I understand that a simple var could be used to add, but i am needing to recall the data from the class, and i am not sure of how to do that could you please provide me with a sample that i can work off, PPPllllease

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Payroll Program 3 question

    am needing to recall the data from the class,
    What variable from what class?

    As christopherx said, you are not using the Employee class at all.

    What is the purpose of the class?
    Where and how do you plan to use it?
    Last edited by Norm; 02-03-2012 at 09:42 PM.

  10. #10
    cloudent01 is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Payroll Program 3 question

    I need the program to recall the person name and pay and have it add each the same name is used, also if a different name is used i want it to display that person's name and pay,

    such as :
    tim 920
    tim 1840 ....
    but if mary is entered
    mary 450
    mary 900
    and if tim is entered again
    tim 2760
    and if mary is entered
    mary 1350

    displayed as:
    "name" has made a total of $"total"
    tim has made a total of $2760

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Payroll Program 3 question

    I need the program to recall the person name and pay
    Where is the person's data to be stored? You have a class that looks like a good place.
    When you get done gathering the data for a person you should create an Employee object with all that data in it.

    Then you will need some kind of container to store the data for each person, link an array or arraylist.

  12. #12
    cloudent01 is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Payroll Program 3 question

    Well that explains it i have not gotten that far in the class, thanks tho, i am going to shoot the teacher now
    i thought that i had it worng

Similar Threads

  1. Replies: 2
    Last Post: 08-01-2011, 12:19 AM
  2. Payroll program.. School.. Help Please!
    By eddyb5 in forum New To Java
    Replies: 2
    Last Post: 06-05-2011, 06:49 PM
  3. payroll program 2
    By joshwey in forum New To Java
    Replies: 13
    Last Post: 05-13-2011, 10:27 AM
  4. Payroll program
    By bigley04 in forum Eclipse
    Replies: 7
    Last Post: 12-06-2010, 05:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •