473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help on simple problem

I need 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. For some
reason Icant seem to grasp this simple task. Can some plese help me
out on this? Thanks

import java.util.Scanner;


public class Payroll


{


public static void main(String[] args)
{


// Variable Declaration
double payrate; // Hourly Rate of employee
double hours; // Hours Worked by employee
double grosspay; // Weekly Pay for employee
Scanner keyboard;


Scanner input = new Scanner( System.in );


// Get employee's name
System.out.printf( "Enter the employee's name(Enter stop when
finished):");


String name = input.next();
while(!name.equals("stop"))


{ // Start of name while loop


// Get hourly rate of employee
System.out.printf( "Enter the employee's hourly pay rate: " );
payrate = input.nextDouble();
while (payrate<=0)
{ // start payrate while loop
System.out.printf("\nPayrate must be positive, try again:");
payrate = input.nextDouble();
} // end of payrate while loop


// Get hours worked for the pay period
System.out.printf( "Enter the number of hours worked in this pay
period: ");
hours = input.nextDouble();
while ( hours <= 0 )
{ // start the hours while loop
System.out.printf( "\nSorry you need to enter a positive
number for the Hours:");
hours = input.nextDouble();
} // end hours while loop


// This calculates the gross pay.
grosspay = hours * payrate;


// Display results and reshows what you have entered
System.out.printf( "\nemployee: %s", name );
System.out.printf( "\nhourly rate: $%.2f", payrate );
System.out.printf( "\nhours worked: $%.2f", hours );
System.out.printf( "\nweekly paycheck: $%.2f\n",grosspay);


System.out.printf( "\n\n\nEnter another employee's name (Enter
stop when finished):");
name = input.next();


}// End of name while loop


}


}
Oct 20 '06 #1
6 2194
r035198x
13,262 8TB
I need 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. For some
reason Icant seem to grasp this simple task. Can some plese help me
out on this? Thanks

import java.util.Scanner;


public class Payroll


{


public static void main(String[] args)
{


// Variable Declaration
double payrate; // Hourly Rate of employee
double hours; // Hours Worked by employee
double grosspay; // Weekly Pay for employee
Scanner keyboard;


Scanner input = new Scanner( System.in );


// Get employee's name
System.out.printf( "Enter the employee's name(Enter stop when
finished):");


String name = input.next();
while(!name.equals("stop"))


{ // Start of name while loop


// Get hourly rate of employee
System.out.printf( "Enter the employee's hourly pay rate: " );
payrate = input.nextDouble();
while (payrate<=0)
{ // start payrate while loop
System.out.printf("\nPayrate must be positive, try again:");
payrate = input.nextDouble();
} // end of payrate while loop


// Get hours worked for the pay period
System.out.printf( "Enter the number of hours worked in this pay
period: ");
hours = input.nextDouble();
while ( hours <= 0 )
{ // start the hours while loop
System.out.printf( "\nSorry you need to enter a positive
number for the Hours:");
hours = input.nextDouble();
} // end hours while loop


// This calculates the gross pay.
grosspay = hours * payrate;


// Display results and reshows what you have entered
System.out.printf( "\nemployee: %s", name );
System.out.printf( "\nhourly rate: $%.2f", payrate );
System.out.printf( "\nhours worked: $%.2f", hours );
System.out.printf( "\nweekly paycheck: $%.2f\n",grosspay);


System.out.printf( "\n\n\nEnter another employee's name (Enter
stop when finished):");
name = input.next();


}// End of name while loop


}


}

Expand|Select|Wrap|Line Numbers
  1. public class Employee {
  2.     String name;
  3.     double payRate; // Hourly Rate of employee
  4.     double hours; // Hours Worked by employee
  5.     double grossPay; // Weekly Pay for employee
  6.  
  7.     public Employee () {
  8.         name = "";
  9.         payRate = 0.0;
  10.         hours = 0.0;
  11.         grossPay = 0.0;
  12.     }
  13.  
  14.     public Employee (String name, double payRate, double hours) {
  15.         this.name = name;
  16.         this.payRate = payRate;
  17.         this.hours = hours;
  18.  
  19.     }
  20.  
  21.     public void calculateGross() {
  22.         grossPay = hours * payRate;
  23.     }
  24.  
  25.     public void setName(String name) {
  26.         this.name = name;
  27.     }
  28.     public void setName(double hours) {
  29.             this.hours = hours;
  30.     }
  31. }
Take it away from here
Oct 21 '06 #2
Expand|Select|Wrap|Line Numbers
  1. public class Employee {
  2.     String name;
  3.     double payRate; // Hourly Rate of employee
  4.     double hours; // Hours Worked by employee
  5.     double grossPay; // Weekly Pay for employee
  6.  
  7.     public Employee () {
  8.         name = "";
  9.         payRate = 0.0;
  10.         hours = 0.0;
  11.         grossPay = 0.0;
  12.     }
  13.  
  14.     public Employee (String name, double payRate, double hours) {
  15.         this.name = name;
  16.         this.payRate = payRate;
  17.         this.hours = hours;
  18.  
  19.     }
  20.  
  21.     public void calculateGross() {
  22.         grossPay = hours * payRate;
  23.     }
  24.  
  25.     public void setName(String name) {
  26.         this.name = name;
  27.     }
  28.     public void setName(double hours) {
  29.             this.hours = hours;
  30.     }
  31. }
Take it away from here
I did this but there is still somthing that I can not get right
Expand|Select|Wrap|Line Numbers
  1.  public class Payroll3
  2.  { // start Payroll3
  3.      public static void main( String args[])
  4.      {
  5.          Employee n = new Employee();
  6.  
  7.          n.showName();
  8.          n.showpayRate();
  9.          n.showHours();
  10.      }
  11.  } // end Payroll3
What am I missing?
Oct 21 '06 #3
r035198x
13,262 8TB
I did this but there is still somthing that I can not get right
Expand|Select|Wrap|Line Numbers
  1.  public class Payroll3
  2.  { // start Payroll3
  3.      public static void main( String args[])
  4.      {
  5.          Employee n = new Employee();
  6.  
  7.          n.showName();
  8.          n.showpayRate();
  9.          n.showHours();
  10.      }
  11.  } // end Payroll3
What am I missing?
You were supposed to add some methods to the Employee class that I gave you first. Did you define methods showName(), showpayRate() and showHours() in the Employee class?
Oct 23 '06 #4
You were supposed to add some methods to the Employee class that I gave you first. Did you define methods showName(), showpayRate() and showHours() in the Employee class?
Now I fell like an idiot, yes that’s what I forgot. Thanks
Oct 23 '06 #5
I can't seem to find what is wrong with this. I know a lot is wrong
by the amounts of errors that are popping up but I can't seem to find
a way to fix them. Can some one please help with my stupid mistakes?
Thanks
Expand|Select|Wrap|Line Numbers
  1.  import java.util.Scanner; 
  2.  class Employee 
  3.  
  4.  
  5.    private double payrate; 
  6.    private double hoursworked; 
  7.    private String name = "blanknow"; 
  8.  
  9.  
  10.  public Employee () 
  11.  { 
  12.   payrate = 0.0; 
  13.   hours = 0.0; 
  14.  } 
  15.  
  16.  
  17.  public void setpayrate(double payrate) 
  18.  { 
  19.   payrate = rate; 
  20.  } 
  21.  
  22.  
  23.   public double getpayrate() 
  24.    { 
  25.       return payrate; 
  26.    } 
  27.    { System.out.printf ( "enter employees payrate"); 
  28.      while (payrate<=0) 
  29.     System.out.printf("\nPayrate must be positive, try again:"); 
  30.         get.payrate = payrate; 
  31.  } 
  32.   public void sethoursworked(double hours) 
  33.    { 
  34.       hoursworked = hours; 
  35.    } 
  36.      public double gethoursworked() 
  37.    { 
  38.       return hoursworked; 
  39.    } 
  40.    { 
  41.      get.hours = hours; 
  42.  System.out.printf( "Enter the number of hours worked in this pay 
  43. period: "); 
  44.         while ( hours <= 0 ) 
  45.     System.out.printf( "\nSorry you need to enter a positive number for 
  46. the Hours:"); 
  47.         get.hours = hours; 
  48.      } 
  49.       public void setname(String name) 
  50.  { 
  51.   get.name = name; 
  52.  System.out.printf( "Enter the employee's name, untill Stop entered"); 
  53.      while (! get.name.equals("Stop")); 
  54.     } 
  55.  public double calculateweeklypay() 
  56.    { 
  57.       return payrate * hoursworked; 
  58.    } 
  59.  
  60.  
  61.  
  62.  
  63. ****************************************** 
  64.  public class Payroll3 
  65.  { // start Payroll3 
  66.  
  67.   public static void main( String args[]) 
  68.   { 
  69.   Scannerinput = new Scanner( System.in ); 
  70.  
  71.  
  72.     Employee myEmployee = new Employee(); 
  73.  
  74.  
  75.    System.out.printf("Employee Payroll calculator\n"); 
  76.  
  77.  
  78.          System.out.print("Enter Employee Pay Rate: "); 
  79.          myEmployee.setpayrate(input.nextDouble()); 
  80.  
  81.  
  82.          System.out.print( "Enter Hours Worked: "); 
  83.          myEmployee.sethoursworked(input.nextDouble()); 
  84.  
  85.  
  86.          System.out.printf("Employee earned " + 
  87. myEmployee.calculateweeklypay() ); 
  88.  
  89.  
  90.   } 
  91.  } // end Payroll3 
  92.  
Oct 25 '06 #6
r035198x
13,262 8TB
You need to revisit the tutorials on getters and setters

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  class Employee {
  3.      private double payrate;
  4.      private double hoursworked;
  5.      private String name = "blanknow";
  6.      public Employee () {
  7.         payrate = 0.0;
  8.           hoursworked = 0.0;//hours or hoursworked?
  9.      }
  10.      public void setpayrate(double rate)// what's coming into the method is rate
  11.     {
  12.         payrate = rate;
  13.      }
  14.      public double getpayrate()
  15.     {
  16.         return payrate;
  17.        }
  18.  
  19.        /*What is all this supposed to be?
  20.    { System.out.printf ( "enter employees payrate");
  21.      while (payrate<=0)
  22.     System.out.printf("\nPayrate must be positive, try again:");
  23.         get.payrate = payrate;
  24.  }*/
  25.   public void sethoursworked(double hours)
  26.    {
  27.       hoursworked = hours;
  28.    }
  29.      public double gethoursworked()
  30.    {
  31.       return hoursworked;
  32.    }
  33.    public void setName(String s) {
  34.        name = s;
  35.    }
  36.  
  37.    /*What is all this supposed to be?
  38.  
  39.    {
  40.      get.hours = hours;
  41.  System.out.printf( "Enter the number of hours worked in this pay period: ");
  42.         while ( hours <= 0 )
  43.     System.out.printf( "\nSorry you need to enter a positive number for the Hours:");
  44.         get.hours = hours;
  45.      }
  46.       public void setname(String name)
  47.  {
  48.   get.name = name;
  49.  System.out.printf( "Enter the employee's name, untill Stop entered");
  50.      while (! get.name.equals("Stop"));
  51.     }*/
  52.  public double calculateweeklypay()
  53.    {
  54.       return payrate * hoursworked;
  55.    }
  56.  
  57.  
  58. }
  59.  
  60.  
  61. //******************************************
  62.  public class Payroll3
  63.  { // start Payroll3
  64.  
  65.   public static void main( String args[])
  66.   {
  67.   Scanner input = new Scanner(System.in);
  68.  
  69.  
  70.     Employee myEmployee = new Employee();
  71.  
  72.  
  73.    System.out.printf("Employee Payroll calculator\n");
  74.  
  75.  
  76.          System.out.print("Enter Employee Pay Rate: ");
  77.          myEmployee.setpayrate(input.nextDouble());
  78.  
  79.  
  80.          System.out.print( "Enter Hours Worked: ");
  81.          myEmployee.sethoursworked(input.nextDouble());
  82.  
  83.  
  84.          System.out.printf("Employee earned " + myEmployee.calculateweeklypay());
  85.  
  86.  
  87.   }
  88.  } // end Payroll3 
Oct 25 '06 #7

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

Similar topics

9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
2
by: | last post by:
Help! I'm new to c++, and am breaking my teeth on MS Visual C++ (bundled within Visual Studio .NET 2003). Am trying to link simple c++ code to fortran dlls created in Compaq Visual Fortran (v6.1)....
2
by: Steve K | last post by:
I got a bit of a problem I like some help on. I'm designing an online training module for people that work in food processing plants. This is my target audience. These workers have little or no...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
2
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: 73k5blazer | last post by:
Hello again all.. We have a giant application from a giant software vendor that has very poor SQL. It's a PLM CAD application, that makes a call to the db for every cad node in the assembly. So...
3
by: zapras | last post by:
I need some help pretty please? :confused: Im very new to vba access and been trying to work out this problem for a couple of hours. It's probably simple for other people to see the problem though....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.