473,320 Members | 1,535 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,320 software developers and data experts.

Payroll Program Java

Hello, I am trying to figure out when I have done wrong or what i have not included in my most recent edit of my payroll code.

My code from last week was

Expand|Select|Wrap|Line Numbers
  1. // Week 2 payroll
  2. // payroll program that calculates weekly pay
  3. // sentinel-controlled repetition
  4. import java.util.Scanner; // program uses class Scanner
  5.  
  6. public class payroll
  7. {
  8.    // main method begins execution of Java application
  9.    public static void main( String args[] )
  10.    {
  11.  
  12.      // create Scanner to obtain input from command window
  13.      Scanner input = new Scanner( System.in );
  14.  
  15.      String name; // employee's name
  16.      double number1; // first number to multiply
  17.      double number2; // second number to multiply
  18.      double product; // product of number1 and number2
  19.  
  20. System.out.print( "Enter employees name or type stop to quit: " ); // prompt user for employee name
  21. name = input.nextLine(); // read input employee name
  22.  
  23. while (!name.equals("stop") )
  24.    {
  25.    System.out.print( "Enter hourly rate: " ); // prompt user for hourly rate
  26.    number1 = input.nextDouble(); // read input hourly rate 
  27.      while ( number1 < 0 )
  28.        {
  29.        System.out.println( "No Negative Numbers, Please type a positive number" );
  30.        System.out.print( "Enter hourly rate: " ); // prompt user for hourly rate
  31.        number1 = input.nextDouble(); // read input hourly rate 
  32.        }
  33.  
  34.  
  35.      System.out.print( "Enter hours worked this week: " ); // prompt user for hours worked 
  36.      number2 = input.nextDouble(); // read input hours worked
  37.      while ( number2 < 0 )
  38.        {
  39.        System.out.println( "No Negative Numbers, Please type a positive number" );
  40.        System.out.print( "Enter hours worked this week: " ); // prompt user for hours worked 
  41.        number2 = input.nextDouble(); // read input hours worked
  42.        }
  43.  
  44.    product = number1 * number2; // multiply hourly rate by hours worked
  45.  
  46.    System.out.printf( "Employee " + name ); // display employee name 
  47.  
  48.    System.out.printf( "\nTotal Pay $" + product ); // display total weekly pay
  49.  
  50.      input = new Scanner( System.in );
  51.  
  52.      System.out.print( "\nEnter employees name or type stop to quit: " ); // prompt user for employee name
  53.      name = input.nextLine(); // read input employee name
  54.    }
  55.  
  56. System.out.println( "Program Ended ~ Good Bye!" );
  57.  
  58. } // end method main
  59.  
  60. } // end class payroll
  61.  
  62.  
And this compiled and ran just fine. This week my instructions were to "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."

here is my current code...

Expand|Select|Wrap|Line Numbers
  1. // Week 4 payroll
  2. // payroll program that calculates weekly pay
  3. // sentinel-controlled repetition
  4. import java.util.Scanner; // program uses class Scanner
  5.  
  6. //Class payroll
  7. public class payroll
  8. {
  9.  
  10.    {
  11.  
  12.    private String employeeName; // name
  13.    private double number1; // rate
  14.    private double number2; // hours
  15.  
  16.    // payroll constructor for name, rate, hours
  17.    public Payroll( String name, double number1, double number2 )
  18.  
  19.      {
  20.        employeename = name;
  21.        rate = number1; 
  22.        hours = number2;
  23.      } // end constructor
  24.  
  25.      //set name
  26.  
  27.      public void setEmployeeName( String name)
  28.  
  29.      {
  30.        employeeName = name;
  31.      } // end set name
  32.  
  33.      // method get employeename
  34.      public String getEmployeeName();
  35.      {
  36.        return employeeName;
  37.      } // end method get employeename
  38.  
  39.      //set rate
  40.      public void setRate( double number1)
  41.      {
  42.        rate = number1;
  43.      } // end set rate
  44.  
  45.  
  46.      // method get rate
  47.      public double getRate();
  48.      {
  49.        return number1;
  50.      } // end method get rate
  51.  
  52.      //set hours
  53.      public void setHours( double number2)
  54.      {
  55.        hours = number2;
  56.      } // end set hours
  57.  
  58.      // method get hours
  59.      public double getHours();
  60.      {
  61.        return number2;
  62.      } // end method get hours
  63.  
  64. public static void main( String args[] )
  65.  
  66.    // begins main section
  67.  
  68.    {
  69.  
  70.      // create Scanner to obtain input from command window
  71.      Scanner input = new Scanner( System.in );
  72.  
  73.      String name; // employee's name
  74.      double number1; // rate to multiply
  75.      double number2; // hours to multiply
  76.      double product; // product of number1 and number2
  77.  
  78. System.out.print( "Enter employees name or type stop to quit: " ); // prompt user for employee name
  79. name = input.nextLine(); // read input employee name
  80.  
  81. while (!name.equals("stop") )
  82.    {
  83.    System.out.print( "Enter hourly rate: " ); // prompt user for hourly rate
  84.    number1 = input.nextDouble(); // read input hourly rate 
  85.      while ( number1 < 0 )
  86.        {
  87.        System.out.println( "No Negative Numbers, Please type a positive number" );
  88.        System.out.print( "Enter hourly rate: " ); // prompt user for hourly rate
  89.        number1 = input.nextDouble(); // read input hourly rate 
  90.        }
  91.  
  92.  
  93.      System.out.print( "Enter hours worked this week: " ); // prompt user for hours worked 
  94.      number2 = input.nextDouble(); // read input hours worked
  95.      while ( number2 < 0 )
  96.        {
  97.        System.out.println( "No Negative Numbers, Please type a positive number" );
  98.        System.out.print( "Enter hours worked this week: " ); // prompt user for hours worked 
  99.        number2 = input.nextDouble(); // read input hours worked
  100.        }
  101.  
  102.    product = number1 * number2; // multiply hourly rate by hours worked
  103.  
  104.    System.out.printf( "Employee " + name ); // display employee name 
  105.  
  106.    System.out.printf( "\nTotal Pay $" + product ); // display total weekly pay
  107.  
  108.      input = new Scanner( System.in );
  109.  
  110.      System.out.print( "\nEnter employees name or type stop to quit: " ); // prompt user for employee name
  111.      name = input.nextLine(); // read input employee name
  112.    }
  113.  
  114. System.out.println( "Program Ended ~ Good Bye!" );
  115.  
  116. } // end method main
  117.  
  118. } // end class payroll

I get the following errors when i try to compile this...



payroll.java:12: illegal start of expression
private String employeeName; // name
^
payroll.java:13: illegal start of expression
private double number1; // rate
^
payroll.java:14: illegal start of expression
private double number2; // hours
^
payroll.java:17: illegal start of expression
public Payroll( String name, double number1, double number2 )
^
payroll.java:17: ')' expected
public Payroll( String name, double number1, double number2 )
^
payroll.java:17: illegal start of expression
public Payroll( String name, double number1, double number2 )
^
payroll.java:17: ';' expected
public Payroll( String name, double number1, double number2 )
^
payroll.java:17: not a statement
public Payroll( String name, double number1, double number2 )
^
payroll.java:17: ';' expected
public Payroll( String name, double number1, double number2 )
^
payroll.java:17: ';' expected
public Payroll( String name, double number1, double number2 )
^
payroll.java:27: illegal start of expression
public void setEmployeeName( String name)
^
payroll.java:27: illegal start of expression
public void setEmployeeName( String name)
^
payroll.java:27: ';' expected
public void setEmployeeName( String name)
^
payroll.java:27: ';' expected
public void setEmployeeName( String name)
^
payroll.java:34: illegal start of expression
public String getEmployeeName();
^
payroll.java:34: ';' expected
public String getEmployeeName();
^
payroll.java:40: illegal start of expression
public void setRate( double number1)
^
payroll.java:40: illegal start of expression
public void setRate( double number1)
^
payroll.java:40: ';' expected
public void setRate( double number1)
^
payroll.java:40: ';' expected
public void setRate( double number1)
^
payroll.java:47: illegal start of expression
public double getRate();
^
payroll.java:47: ';' expected
public double getRate();
^
payroll.java:53: illegal start of expression
public void setHours( double number2)
^
payroll.java:53: illegal start of expression
public void setHours( double number2)
^
payroll.java:53: ';' expected
public void setHours( double number2)
^
payroll.java:53: ';' expected
public void setHours( double number2)
^
payroll.java:59: illegal start of expression
public double getHours();
^
payroll.java:59: ';' expected
public double getHours();
^
payroll.java:64: illegal start of expression
public static void main( String args[] )
^
payroll.java:64: illegal start of expression
public static void main( String args[] )
^
payroll.java:64: ';' expected
public static void main( String args[] )
^
payroll.java:64: ')' expected
public static void main( String args[] )
^
payroll.java:64: illegal start of expression
public static void main( String args[] )
^
payroll.java:64: ';' expected
public static void main( String args[] )
^
payroll.java:64: illegal start of expression
public static void main( String args[] )
^
payroll.java:64: ';' expected
public static void main( String args[] )
^
36 errors
Jan 25 '10 #1
2 16689
Markus
6,050 Expert 4TB
Hi, alexlunar. Welcome to the forums.

First off, I'd like to point you to our Forum Guidelines, specifically the section on Posting Code. Please remember to use [code] tags.

Secondly, to your problem, it looks like you have a rogue curly bracket on line 10 of the new code. Remove this and you should be good to go.

Mark.
Jan 25 '10 #2
there is no main method in that code...
Mar 23 '12 #3

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

Similar topics

1
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...
10
by: ycg0771 | last post by:
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...
5
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
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...
1
by: Richards | last post by:
Pls help me with code for a payroll in c++. how to declare my variable and use functions to segment the program. thanks Richards
8
by: teddarr | last post by:
I have a program that uses Employee as the superclass. It has subclasses of SalariedEmployee, CommissionEmployee, BasePlusCommissionEmployee, and HoulyEmployee. This program works great to provide...
6
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.