473,499 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Requesting help for payroll program.

5 New Member
I'm trying to modify the following 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. It seems that the more I read into this, the more confused I get. Any help will be greatly apreciated.
Here is my latest code...

Expand|Select|Wrap|Line Numbers
  1. // Payroll program that calculates an employee's weekly pay.
  2.  
  3. import java.util.Scanner; // program uses class Scanner
  4.  
  5. class EmployeeData {
  6.     EmployeeData(String newName, float newHourlyRate, float newHoursWorked) {
  7.         name = newName;  hourlyRate = newHourlyRate;  hoursWorked = newHoursWorked;
  8.     }
  9.  
  10.     public String getName() { return name; }
  11.     public float getWeeklyPay() { return hourlyRate * hoursWorked; }
  12.  
  13.     private String name;
  14.     private float hourlyRate, hoursWorked;
  15. } // end of EmployeeData class
  16.  
  17. public class Payroll3
  18. {
  19.    private String EmployeeData; // employee information for this Payroll
  20.  
  21.    // main method begins execution of java application
  22.    public static void main( String args[] )
  23.    {
  24.         boolean stop = false; // This flag will control whether we exit the loop below
  25.  
  26.         // Loop until user types "stop" as the employee name:
  27.         while (!stop)
  28.         {     
  29.             // create scanner to obtain input from command window
  30.             Scanner input = new Scanner ( System.in );
  31.  
  32.             System.out.println();  // outputs a blank line
  33.             System.out.print( "Please enter the employee name or 'stop' to end program: " ); // prompt
  34.             String empName = input.nextLine(); // read employee name
  35.  
  36.             if ( empName.compareTo("stop") == 0) // Check whether user indicated to stop program
  37.             {
  38.                 System.out.println( "Program ended." );
  39.                 stop = true;
  40.             }
  41.              else
  42.              {
  43.                    // User did not indicate to stop, so continue reading info for this iteration:
  44.                 EmployeeData employee;
  45.                 float hourlyRate; // first number to multiply
  46.                 float hoursWorked; // second number to multiply
  47.                 float weeklyPay; // product of hourlyRate and hoursWorked
  48.  
  49.                 System.out.print( "Please enter hourly rate: $" ); // prompt
  50.                 hourlyRate = input.nextFloat(); // read hourly rate from user
  51.                 while (hourlyRate <= 0) // prompt until a positive value is entered
  52.                 {
  53.                     System.out.print( "Hourly rate must be a positive value. " +
  54.                        "Please enter the hourly rate again: $" ); // prompt for positive value for hourly rate
  55.                     hourlyRate = input.nextFloat(); // read hourly rate again
  56.                 }
  57.  
  58.                   System.out.print( "Please enter hours worked: " ); // prompt
  59.                   hoursWorked = input.nextFloat(); // read number of hours worked from user
  60.                   while (hoursWorked <= 0) // prompt until a positive value is entered
  61.                   {
  62.                      System.out.print( "Hours worked must be a positive value. " +
  63.                            "Please enter the hours worked again: " ); // prompt for positive value for hours worked
  64.                       hoursWorked = input.nextFloat(); // read hours worked again
  65.                   }
  66.  
  67.                  employee = new EmployeeData(empName, hourlyRate, hoursWorked);
  68.                   ///weeklyPay = hourlyRate * hoursWorked; // multiply
  69.  
  70.                   System.out.print( employee.getName() ); // display employee name
  71.                   System.out.printf( "'s weekly pay is: $%,.2f\n", employee.getWeeklyPay() );  // display weekly pay
  72.  
  73.         }
  74.       }
  75.  
  76.    } // end method main
  77.  
  78. } // end class Payroll3
Dec 6 '06 #1
10 7622
DeMan
1,806 Top Contributor
What appears to be the problem, the EmployeeData class seems to do everything you have asked....

I assume you need help with the main body of the program, but could you please specify what is the problem you are having....
Dec 6 '06 #2
zaidalin79
59 New Member
I think we might be in the same class... I am trying to figure these things out too... I will try to help you as I get them...
Dec 6 '06 #3
r035198x
13,262 MVP
To store the Employers's data, you neen an ArrayList not a String.


Expand|Select|Wrap|Line Numbers
  1.  
  2. // Payroll program that calculates an employee's weekly pay.
  3. import java.util.*; // program uses class Scanner 
  4. class EmployeeData {
  5.  EmployeeData(String newName, float newHourlyRate, float newHoursWorked) {
  6.   name = newName;
  7.   hourlyRate = newHourlyRate;
  8.   hoursWorked = newHoursWorked;
  9.  }
  10.  public String getName() {
  11.   return name;
  12.  }
  13.  public float getWeeklyPay() {
  14.   return hourlyRate * hoursWorked;
  15.  }
  16.  private String name;
  17.  private float hourlyRate, hoursWorked;
  18. } // end of EmployeeData class
  19. public class Payroll3
  20. {
  21.  
  22.    // main method begins execution of java application
  23.    public static void main( String args[] )
  24.    {
  25.      ArrayList employees = new ArrayList(); // employee information for this Payroll you need to be able to store many employees
  26.   boolean stop = false; // This flag will control whether we exit the loop below
  27.   // Loop until user types "stop" as the employee name:
  28.   while (!stop)
  29.   {
  30.    // create scanner to obtain input from command window
  31.    Scanner input = new Scanner ( System.in );
  32.    System.out.println();  // outputs a blank line
  33.    System.out.print( "Please enter the employee name or 'stop' to end program: " ); // prompt
  34.    String empName = input.nextLine(); // read employee name
  35.    if ( empName.compareTo("stop") == 0) // Check whether user indicated to stop program
  36.    {
  37.     System.out.println( "Program ended." );
  38.     stop = true;
  39.    }
  40.     else
  41.     {
  42.        // User did not indicate to stop, so continue reading info for this iteration:
  43.     EmployeeData employee;
  44.     float hourlyRate; // first number to multiply
  45.     float hoursWorked; // second number to multiply
  46.     float weeklyPay; // product of hourlyRate and hoursWorked
  47.     System.out.print( "Please enter hourly rate: $" ); // prompt
  48.     hourlyRate = input.nextFloat(); // read hourly rate from user
  49.     while (hourlyRate <= 0) // prompt until a positive value is entered
  50.           {
  51.            System.out.print( "Hourly rate must be a positive value. " +
  52.                  "Please enter the hourly rate again: $" ); // prompt for positive value for hourly rate
  53.               hourlyRate = input.nextFloat(); // read hourly rate again
  54.           }
  55.             System.out.print( "Please enter hours worked: " ); // prompt
  56.             hoursWorked = input.nextFloat(); // read number of hours worked from user
  57.             while (hoursWorked <= 0) // prompt until a positive value is entered
  58.             {
  59.                System.out.print( "Hours worked must be a positive value. " +
  60.                   "Please enter the hours worked again: " ); // prompt for positive value for hours worked
  61.                 hoursWorked = input.nextFloat(); // read hours worked again
  62.             }
  63.      employee = new EmployeeData(empName, hourlyRate, hoursWorked);
  64.             ///weeklyPay = hourlyRate * hoursWorked; // multiply
  65.             System.out.print( employee.getName() ); // display employee name
  66.             System.out.printf( "'s weekly pay is: $%,.2f\n", employee.getWeeklyPay() );  // display weekly pay
  67.             employees.add(employee);
  68.         }
  69.       }
  70.       //You can do additional stuff with the employees here
  71.  
  72.    } // end method main
  73. } // end class Payroll3
  74.  
Dec 6 '06 #4
ycg0771
5 New Member
To store the Employers's data, you neen an ArrayList not a String.


Expand|Select|Wrap|Line Numbers
  1.  
  2. // Payroll program that calculates an employee's weekly pay.
  3. import java.util.*; // program uses class Scanner 
  4. class EmployeeData {
  5.  EmployeeData(String newName, float newHourlyRate, float newHoursWorked) {
  6.   name = newName;
  7.   hourlyRate = newHourlyRate;
  8.   hoursWorked = newHoursWorked;
  9.  }
  10.  public String getName() {
  11.   return name;
  12.  }
  13.  public float getWeeklyPay() {
  14.   return hourlyRate * hoursWorked;
  15.  }
  16.  private String name;
  17.  private float hourlyRate, hoursWorked;
  18. } // end of EmployeeData class
  19. public class Payroll3
  20. {
  21.  
  22.    // main method begins execution of java application
  23.    public static void main( String args[] )
  24.    {
  25.      ArrayList employees = new ArrayList(); // employee information for this Payroll you need to be able to store many employees
  26.   boolean stop = false; // This flag will control whether we exit the loop below
  27.   // Loop until user types "stop" as the employee name:
  28.   while (!stop)
  29.   {
  30.    // create scanner to obtain input from command window
  31.    Scanner input = new Scanner ( System.in );
  32.    System.out.println();  // outputs a blank line
  33.    System.out.print( "Please enter the employee name or 'stop' to end program: " ); // prompt
  34.    String empName = input.nextLine(); // read employee name
  35.    if ( empName.compareTo("stop") == 0) // Check whether user indicated to stop program
  36.    {
  37.     System.out.println( "Program ended." );
  38.     stop = true;
  39.    }
  40.     else
  41.     {
  42.        // User did not indicate to stop, so continue reading info for this iteration:
  43.     EmployeeData employee;
  44.     float hourlyRate; // first number to multiply
  45.     float hoursWorked; // second number to multiply
  46.     float weeklyPay; // product of hourlyRate and hoursWorked
  47.     System.out.print( "Please enter hourly rate: $" ); // prompt
  48.     hourlyRate = input.nextFloat(); // read hourly rate from user
  49.     while (hourlyRate <= 0) // prompt until a positive value is entered
  50.           {
  51.            System.out.print( "Hourly rate must be a positive value. " +
  52.                  "Please enter the hourly rate again: $" ); // prompt for positive value for hourly rate
  53.               hourlyRate = input.nextFloat(); // read hourly rate again
  54.           }
  55.             System.out.print( "Please enter hours worked: " ); // prompt
  56.             hoursWorked = input.nextFloat(); // read number of hours worked from user
  57.             while (hoursWorked <= 0) // prompt until a positive value is entered
  58.             {
  59.                System.out.print( "Hours worked must be a positive value. " +
  60.                   "Please enter the hours worked again: " ); // prompt for positive value for hours worked
  61.                 hoursWorked = input.nextFloat(); // read hours worked again
  62.             }
  63.      employee = new EmployeeData(empName, hourlyRate, hoursWorked);
  64.             ///weeklyPay = hourlyRate * hoursWorked; // multiply
  65.             System.out.print( employee.getName() ); // display employee name
  66.             System.out.printf( "'s weekly pay is: $%,.2f\n", employee.getWeeklyPay() );  // display weekly pay
  67.             employees.add(employee);
  68.         }
  69.       }
  70.       //You can do additional stuff with the employees here
  71.  
  72.    } // end method main
  73. } // end class Payroll3
  74.  
Thank you, but this outputs a note of "uses unchecked or unsafe operations".
Dec 6 '06 #5
ycg0771
5 New Member
I think we might be in the same class... I am trying to figure these things out too... I will try to help you as I get them...
Thank you. I wasn't doing too bad in this class until this past week. I was ill for three days and I guess it threw me off track more than I ever imagined.
Dec 6 '06 #6
ycg0771
5 New Member
What appears to be the problem, the EmployeeData class seems to do everything you have asked....

I assume you need help with the main body of the program, but could you please specify what is the problem you are having....
You are correct. I thought I had a problem here, but after going through it once again, step by step, the code works as it should. I hate to admit it, but my husband must be right when he tells me that I make things harder than what they really are. I apologize for wasting everyone's time here.
Thank you.
Dec 6 '06 #7
r035198x
13,262 MVP
You are correct. I thought I had a problem here, but after going through it once again, step by step, the code works as it should. I hate to admit it, but my husband must be right when he tells me that I make things harder than what they really are. I apologize for wasting everyone's time here.
Thank you.
No you did not waste anyone's time
Dec 7 '06 #8
ycg0771
5 New Member
No you did not waste anyone's time
Thank you.
Dec 8 '06 #9
deepslp
1 New Member
Ok so I’m in this same class and your posts really helped allot. I just want to know how do I not plagiarize the work that was done by someone else if we all have to write the same application? I’m about to turn mine in and it’s almost a copy/paste of the code above even though I wrote it all out.
Jan 20 '07 #10
Ganon11
3,652 Recognized Expert Specialist
Ok so I’m in this same class and your posts really helped allot. I just want to know how do I not plagiarize the work that was done by someone else if we all have to write the same application? I’m about to turn mine in and it’s almost a copy/paste of the code above even though I wrote it all out.
If you've written the code by yourself, I wouldn't be terribly worried about it. Some simple programs have just about 1 solution, and every code solving that problem will look similar, if not identical. As long as your code works and you know you've written it yourself and thought the whole process through thoroughly, I think you'll be fine.
Jan 21 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
8638
by: Randi | last post by:
Hi, Looking for some help with this payrool project I have for class. This is what the instructor asks for so far. I have it working without errors but am getting some funky numbers. I am not...
0
1458
by: zexx | last post by:
Need some advise.... Payroll program Access97. Payroll is printed then posted to a hx table thro' a query with the payroll calculations that freeze that payroll's numbers for that period. The...
1
5295
by: cheungs7 | last post by:
Hi all, Wondering whether you can anyone help me. We have Sage Payroll (and accounting/payroll software), which has a MS Access database where the data is stored. Now I want to access the...
1
1572
by: Akinyemi | last post by:
I am developing a payroll program.. The data generated will be saved in an Access Database. I want a situation whereby when an employee leaves the organization or retires, instead of deleting his...
2
1431
by: Akinyemi | last post by:
I have been trying to develop a Payroll Program, but Iam having difficuty in doing so. Please can any member recomend any good Visual Basic 6 book on Payroll Programming? I shall appreciate your...
8
2902
by: John Sitka | last post by:
Hi, There are four pay types standard shiftpremium doubletime doubletimepremium each hour a person books can be one of these types
5
11612
by: jbailey006 | last post by:
I am trying to add the following information to a payroll program I am working on for assignment. Modify the Payroll Program so that it uses a class to store and retrieve the employee's name, the...
1
1593
by: Akinyemi | last post by:
I have almost finished writing my Payroll Program. But I am wondering how the program can be used for different months. For example, after, say January 2007 Payroll, the user would want to prepare...
6
5424
by: aureao4 | last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to add set, get and a class. I've written the class...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.