5 Replies - 2730 Views - Last Post: 04 November 2008 - 12:55 PM Rate Topic: -----

#1 confuzzled153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-November 08

Payroll Program Java Code - Please help, hope is lost

Post icon  Posted 04 November 2008 - 11:13 AM

I have tried so many times to redo this program. I know the problem is that I am not transferring variables the way I'm supposed to between classes and methods. I have even tried to keep the whole program in one class to make things easier but it isn't working very well. I need a good explanation of passing parameters I think. You will notice that I have a bunch of commented code as well because I cannot get the variables to pass, so the output is beign fudgy. I just need to get the computation to work and then I will deal with the other problems. This is due tomorrow :( I tried all by myself but I've given up hope at this point and am ready to turn in a non-working program just for partial credit. I don't want anyone to do this for me but I need a good helping out. If part is shown, I can probably figure it out from there.

Version 1, most recent
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; 

public class PayrollProcessor extends JFrame
{
   private final double SOCIAL_SECURITY_TAX_RATE = .062;
   private final double MEDICARE_TAX_RATE = .0145;
   private double FUTA_RATE = .008;
	
   private String employeeLastName;
   private String employeeFirstName;
   private String employeeFullName;

   private double employeePayRate;
   private String employeeFileStatus;
   private int employeeExemptions;

   private double employeeAddlWH;
   private String employeeTaxStatus;

   private double SUTA_Tax_Rate;
   private String companyName;
	  
   private double regularGross;
   private double overtimeGross;
   private double totalGross;
   private double netPay;
   private double SSTaxWH;
   private double MedTaxWH;
   private double fedWH;
   private double addlFedWH;
   private double futaTax;
   private double sutaTax;
   private double totalWH; 
   private double totalEmployerTaxes;
	  
   private double regularHours;
   private double overtimeHours;

 private JLabel coNameL;
 private JLabel coSutaL; 
 private JLabel empLastL;
 private JLabel empFirstL;
 private JLabel empPayRateL;
 private JLabel empFileStatusL;
 private JLabel empExemptL;
 private JLabel empAddlWHL;
 private JLabel regHoursL;
 private JLabel otHoursL;
 private JLabel fedWHL;
	 
 private JTextField coNameTF;
 private JTextField coSutaTF;
 private JTextField empLastTF;
 private JTextField empFirstTF;
 private JTextField empPayRateTF;
 private JTextField empFileStatusTF;
 private JTextField empExemptTF;
 private JTextField empAddlWHTF;
 private JTextField regHoursTF;
 private JTextField otHoursTF;
 private JTextField fedWHTF;
	
 private JButton exitButton, calculateButton;
  
 private ExitHandler exitBtnHandler;
 private CalculateHandler calcBtnHandler;
 
 public static void main(String[] args)
 {
 PayrollProcessor mainProgram = new PayrollProcessor();
 }
  
// constructor to setup window
 public PayrollProcessor()
 {
 setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
 } 
 
 // method for setting up window
 public void setupWindow(String company, double sutRate, String last,
						 String first, double rate, String fileStat,
								 int exempt, double addl, double regHr, 
								 double otHr, double federalWH)
 {
  setTitle("Simple Payroll Processing Application");
  setSize(700, 500);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true);
  
  Container pane = getContentPane();
  
  pane.setLayout(new GridLayout(12,2));
  
  coNameL = new JLabel("Company Name: ", SwingConstants.RIGHT);
  coNameTF = new JTextField(35);
	
  coSutaL = new JLabel("Company SUTA Rate: ", SwingConstants.RIGHT);
  coSutaTF = new JTextField(5);
	  
  empLastL = new JLabel("Employee Last Name :", SwingConstants.RIGHT);
  empLastTF = new JTextField(25);
  
  empFirstL = new JLabel("Employee First Name: ", SwingConstants.RIGHT);
  empFirstTF = new JTextField(20);
  
  empPayRateL = new JLabel("Employee Pay Rate: ", SwingConstants.RIGHT);
  empPayRateTF = new JTextField(6);
  
  empFileStatusL = new JLabel("Employee Filing Status: ", SwingConstants.RIGHT);	  
  empFileStatusTF = new JTextField(20);
  
  empExemptL = new JLabel("Number of Exemptions: ", SwingConstants.RIGHT);
  empExemptTF = new JTextField(2);
  
  empAddlWHL = new JLabel("If any, enter additional withholding: ", SwingConstants.RIGHT);
  empAddlWHTF = new JTextField(6);
		  
  regHoursL = new JLabel("How many regular hours were worked :", SwingConstants.RIGHT);
  regHoursTF = new JTextField(2);
  otHoursL = new JLabel("How many overtime hours were worked: ", SwingConstants.RIGHT);
  otHoursTF = new JTextField(2);
	  
  fedWHL = new JLabel("How much federal withholding: ", SwingConstants.RIGHT);
  fedWHTF = new JTextField(6);
  
  calculateButton = new JButton("Calculate");
  calcBtnHandler = new CalculateHandler();
  calculateButton.addActionListener(calcBtnHandler);
	  
  exitButton = new JButton("Exit");
  exitBtnHandler = new ExitHandler();
  exitButton.addActionListener(exitBtnHandler);

  pane.add(coNameL);
  pane.add(coNameTF);
  pane.add(coSutaL);
  pane.add(coSutaTF);
  pane.add(empLastL);
  pane.add(empLastTF);
  pane.add(empFirstL);
  pane.add(empFirstTF);
  pane.add(empPayRateL);
  pane.add(empPayRateTF);
  pane.add(empFileStatusL);
  pane.add(empFileStatusTF);
  pane.add(empExemptL);
  pane.add(empExemptTF);
  pane.add(empAddlWHL);
  pane.add(empAddlWHTF);
  pane.add(regHoursL);
  pane.add(regHoursTF);
  pane.add(otHoursL);
  pane.add(otHoursTF);
  pane.add(fedWHL);
  pane.add(fedWHTF);
	  
  pane.add(calculateButton);
  pane.add(exitButton);
  
	 companyName =(coNameTF.getText()); 
	  companyName = company;
	  
	  SUTA_Tax_Rate = Double.parseDouble(coSutaTF.getText());
	  SUTA_Tax_Rate = sutRate;
	  
	 employeeLastName = (empLastTF.getText());
	  employeeLastName = last;
	  
	 employeeFirstName = (empFirstTF.getText());
	  employeeFirstName = first;
	  
	 employeePayRate = Double.parseDouble(empPayRateTF.getText());
	  employeePayRate = rate;
	  
	  employeeFileStatus =(empFileStatusTF.getText());
	  employeeFileStatus = fileStat;
	  
	 employeeExemptions = Integer.parseInt(empExemptTF.getText());
	  employeeExemptions = exempt;
	  
	 employeeAddlWH =Double.parseDouble(empAddlWHTF.getText());
	 employeeAddlWH = addl;
		   
	 regularHours = Double.parseDouble(regHoursTF.getText());
	  regularHours = regHr;
	  
	 overtimeHours = Double.parseDouble(otHoursTF.getText());
	  overtimeHours = otHr;
	  
	  fedWH = Double.parseDouble(fedWHTF.getText());
	 fedWH = federalWH;

 }// end of method to setup window
 
 // setup calculateResults method
 public void calculateResults(String company, String employee, String taxStatus,
							  double regGross, double otGross, double totGross,
										double socSec, double medicare, double federal,
										double addlFederal, double totalTaxes, double net,
										double futa, double suta, double totalEmployer)
 {		
 	String outputStr;

 	outputStr = " ";  
	employeeLastName=" ";
   employeeFirstName=" ";
   employeeFullName=" ";
   employeePayRate=0;
   employeeFileStatus=" ";
   employeeExemptions=0;
   employeeTaxStatus=" ";
   employeeAddlWH=0;

   SUTA_Tax_Rate=0;
   companyName=" ";
	  
   regularGross = 0;
   overtimeGross = 0;
   totalGross = 0;
		  
   netPay = 0;
   SSTaxWH = 0;
   MedTaxWH = 0;
   fedWH = 0;
   addlFedWH = 0;
   futaTax = 0;
   sutaTax = 0;

   totalWH = 0;
   totalEmployerTaxes = 0; 
	
   regularHours = 0;
   overtimeHours = 0;
	
   regularGross = regularHours * employeePayRate;
   overtimeGross = overtimeHours * (employeePayRate * 1.5);
   totalGross = regularGross + overtimeGross;
   SSTaxWH = totalGross * SOCIAL_SECURITY_TAX_RATE;
   MedTaxWH = totalGross * MEDICARE_TAX_RATE;
		 
   sutaTax = totalGross * SUTA_Tax_Rate;
   futaTax = totalGross * FUTA_RATE;
   totalEmployerTaxes = sutaTax + futaTax + SSTaxWH + MedTaxWH;
	 
   totalWH = SSTaxWH - MedTaxWH - fedWH - addlFedWH;
   netPay = totalGross - totalWH;

   String exemptString = Integer.toString(employeeExemptions);
	   
   employeeFullName = employeeLastName + ", " + employeeFirstName;
   employeeTaxStatus = employeeFileStatus + " - " + exemptString;
	
	companyName = company;
	employeeFullName = employee;
	employeeTaxStatus = taxStatus;
   regularGross = regGross; 
	overtimeGross = otGross;
	totalGross = totGross;
	SSTaxWH = socSec;
	MedTaxWH = medicare; 
	fedWH = federal;
	addlFedWH = addlFederal; 
	totalWH = totalTaxes; 
	netPay = net;
	futaTax = futa; 
	sutaTax = suta; 
	totalEmployerTaxes = totalEmployer;
	
	//output results to screen
   outputStr = 
	 "				  Company Name: " 
	 + String.format("%35s", companyName) + "\n" +
	"				 Employee Name: " 
	 + String.format("%35s", employeeFullName) + "\n" +
	"	Filing Status & Exemptions: " 
	 + String.format("%35s", employeeTaxStatus) + "\n\n" +
	"			 Regular Gross Pay: " 
	 + String.format("%35.2f", regularGross) + "\n" +
	"			Overtime Gross Pay: $ " 
	 + String.format("%35.2f", overtimeGross) + "\n" +
	"			   Total Gross Pay: $ " 
	 + String.format("%35.2f", totalGross) + "\n\n" +
	"  Social Security Tax Withheld: $ " 
	 + String.format("%.2f", SSTaxWH) + "\n" +
	"		 Medicare Tax Withheld: $ " 
	 + String.format("%35.2f", MedTaxWH) + "\n" +
	"		  Federal Tax Withheld: $ " 
	 + String.format("%35.2f", fedWH) + "\n" +
	"Additional Federal Withholding: $ " 
	 + String.format("%35.2f", addlFedWH) + "\n" +
	"		  Total Taxes Withheld: $ " 
	 + String.format("%35.2f", totalWH) + "\n\n" +
	"					 Net pay is $ "
	 + String.format("%35.2f", netPay) + "\n" +
	"EMPLOYER TAXES\n\n" 
	 +
	"	  Federal Unemployment Tax: $ " 
	 + String.format("%35.2f", futaTax) + "\n" +
	"		State Unemployment Tax: $ " 
	 + String.format("%35.2f", sutaTax) + "\n" +
	"		   Social Security Tax: $ " 
	 + String.format("%35.2f", SSTaxWH) + "\n" +
	"				  Medicare Tax: $ " 
	 + String.format("%35.2f", MedTaxWH) +  "\n" +
	"		  Total Employer Taxes: $ " 
	 + String.format("%35.2f",totalEmployerTaxes);

	JOptionPane.showMessageDialog(null, outputStr, "RESULTS", JOptionPane.INFORMATION_MESSAGE);
 }// end calculateResults method
 
//  public void printStars()
//  {
//	  int i;
// 	
//	 for(i=0; i <= 70; i++)
//	{
//	 outFile.print("*");
//	 i++;
//	}
// }
//  public void outputResults()
//  {
//   // start of output to file
//	outFile.printf("%n%n", companyName);
//	outFile.println("Employee Payroll Report" + "		 " + 
//		  "Pay Period: " + "		  Check Date: 10/24/08");
//	outFile.println();
//	outFile.println("							  Report Date: October 24, 2008");
// 
// 		printStars();
// 
//	outFile.println();
//	outFile.printf("Employee Name: %24%n", employeeFullName);
//	outFile.printf("Filing Status: %24%n", employeeFileStatus);
//	outFile.printf("Exemptions:%24%n", employeeExemptions);
//	
// 		printStars();
//   
//		  outFile.println();
//	outFile.printf("Regular Pay Rate: $ %23.2			 Hours: %51.2" + 
// 				   "		  Regular Gross: $ %80.2%n", employeePayRate, +
// 						regularHours, regularGross);
//	outFile.printf("Overtime Pay Rate: $ %23.2			Hours: %51.2" + 
// 				   "		 Overtime Gross: $ %80.2%n", (employeePayRate * 1.5), +
// 						overtimeHours, overtimeGross);
//	outFile.printf("								Total Hours: %51.2" + 
// 				   "			Total Gross: $ %80.2%n", (regularHours + overtimeHours), 
// 						(regularGross + overtimeGross));
//	
// 		printStars();
//  }

//setup nested CalculateHandler class
private class CalculateHandler implements ActionListener 
 {
  public void actionPerformed(ActionEvent e)  
  {	
	calculateResults(String,String, String, double, double, double, 
					  double, double, double, double, double, double, 
							double, double, double);
// 	outputResults();
  }
}// end CalculateHandler class

//setup nested ExitHandler class
private class ExitHandler implements ActionListener
 {
 public void actionPerformed(ActionEvent e)
  {
   JOptionPane.showMessageDialog(null, "Thank you for using Simple Payroll " +
								 "Processing Program", "Program Exit", 
								 JOptionPane.INFORMATION_MESSAGE);
   System.exit(0);
  }
 }// end ExitHandler class
 
}// end PayrollProcessor class




Error messages:
PayrollProcessor.java:80: '.class' expected
setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
^
PayrollProcessor.java:80: '.class' expected
setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
^
PayrollProcessor.java:80: '.class' expected
setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
^
PayrollProcessor.java:80: '.class' expected
setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
^
PayrollProcessor.java:80: '.class' expected
setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
^
PayrollProcessor.java:80: '.class' expected
setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
^
PayrollProcessor.java:80: '.class' expected
setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
^
PayrollProcessor.java:80: '.class' expected
setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
^
PayrollProcessor.java:362: '.class' expected
calculateResults(String,String, String, double, double, double,
^
PayrollProcessor.java:362: '.class' expected
calculateResults(String,String, String, double, double, double,
^
PayrollProcessor.java:362: '.class' expected
calculateResults(String,String, String, double, double, double,
^
PayrollProcessor.java:363: '.class' expected
double, double, double, double, double, double,
^
PayrollProcessor.java:363: '.class' expected
double, double, double, double, double, double,
^
PayrollProcessor.java:363: '.class' expected
double, double, double, double, double, double,
^
PayrollProcessor.java:363: '.class' expected
double, double, double, double, double, double,
^
PayrollProcessor.java:363: '.class' expected
double, double, double, double, double, double,
^
PayrollProcessor.java:363: '.class' expected
double, double, double, double, double, double,
^
PayrollProcessor.java:364: '.class' expected
double, double, double);
^
PayrollProcessor.java:364: '.class' expected
double, double, double);
^
PayrollProcessor.java:364: '.class' expected
double, double, double);
^
20 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

Is This A Good Question/Topic? 0
  • +

Replies To: Payroll Program Java Code - Please help, hope is lost

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Payroll Program Java Code - Please help, hope is lost

Posted 04 November 2008 - 11:53 AM

ok to know how to pass parameters to a method, first you need to know how to write a method....methods are declared using an access modifier, return type, name then a parenthesis with the a parameter list if any...a method would look like this
public static int Number( int n )
{
  return n;
}


public: access modifier
static: its a class method(does not need to be invoked on an object)
int: return type( if you dont wish to return anything from your method then write void instead)
Number: name of the method which you will use to call

now to call a method, first if its an instance method then u should create an object first before you can call it and then u can call it like this
 Object.MethodWhatever( args );


to call a class method, you call it like this
Method( args );
//or
Classname.Method( args );


the args is the values that u pass to the method depending on the parameter list that you have defined in your method declaration...if the method takes 2 numbers, then u should pass 2 numbers to ur method, if its a number and a string, then u should pass a number and a string( note that u should pass the values to ur method in the SAME order they were declared in the method declaration)
hope this helped

This post has been edited by mostyfriedman: 04 November 2008 - 11:54 AM

Was This Post Helpful? 0
  • +
  • -

#3 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: Payroll Program Java Code - Please help, hope is lost

Posted 04 November 2008 - 12:00 PM

where do the paramaters to be passed come from

public PayrollProcessor()
{
	setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
}



???
Was This Post Helpful? 0
  • +
  • -

#4 confuzzled153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-November 08

Re: Payroll Program Java Code - Please help, hope is lost

Posted 04 November 2008 - 12:19 PM

View Postbbq, on 4 Nov, 2008 - 11:00 AM, said:

where do the paramaters to be passed come from

public PayrollProcessor()
{
	setupWindow(String, double, String, String, double, String, int, double, double, double, double, double);
}



???


In this case, it was from the setupWindow method, which I have to check to see if I declared properly now. Reading first response to check to see if I did.
Was This Post Helpful? 0
  • +
  • -

#5 confuzzled153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-November 08

Re: Payroll Program Java Code - Please help, hope is lost

Posted 04 November 2008 - 12:32 PM

View Postmostyfriedman, on 4 Nov, 2008 - 10:53 AM, said:

ok to know how to pass parameters to a method, first you need to know how to write a method....methods are declared using an access modifier, return type, name then a parenthesis with the a parameter list if any...a method would look like this
public static int Number( int n )
{
  return n;
}


public: access modifier
static: its a class method(does not need to be invoked on an object)
int: return type( if you dont wish to return anything from your method then write void instead)
Number: name of the method which you will use to call

now to call a method, first if its an instance method then u should create an object first before you can call it and then u can call it like this
 Object.MethodWhatever( args );


to call a class method, you call it like this
Method( args );
//or
Classname.Method( args );


the args is the values that u pass to the method depending on the parameter list that you have defined in your method declaration...if the method takes 2 numbers, then u should pass 2 numbers to ur method, if its a number and a string, then u should pass a number and a string( note that u should pass the values to ur method in the SAME order they were declared in the method declaration)
hope this helped


I must be more confused than I thought because I thought thats what I did. Basically in this case, I need the results from calculation to be passed back to be able to be used in the output, and I thought that's what I did. Can you tell me where I'm wrong here? I thought my methods were declared properly and everything and I also created the instance of the program and it didn't work, I got even more error messages :(


View Postmostyfriedman, on 4 Nov, 2008 - 10:53 AM, said:

ok to know how to pass parameters to a method, first you need to know how to write a method....methods are declared using an access modifier, return type, name then a parenthesis with the a parameter list if any...a method would look like this
public static int Number( int n )
{
  return n;
}


public: access modifier
static: its a class method(does not need to be invoked on an object)
int: return type( if you dont wish to return anything from your method then write void instead)
Number: name of the method which you will use to call

now to call a method, first if its an instance method then u should create an object first before you can call it and then u can call it like this
 Object.MethodWhatever( args );


to call a class method, you call it like this
Method( args );
//or
Classname.Method( args );


the args is the values that u pass to the method depending on the parameter list that you have defined in your method declaration...if the method takes 2 numbers, then u should pass 2 numbers to ur method, if its a number and a string, then u should pass a number and a string( note that u should pass the values to ur method in the SAME order they were declared in the method declaration)
hope this helped


I went back and added static to my methods but it didn't help, I get the same error messages :(
Was This Post Helpful? 0
  • +
  • -

#6 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Payroll Program Java Code - Please help, hope is lost

Posted 04 November 2008 - 12:55 PM

ok in the contructor you have written you should provide it with a parameter list, otherwise how will you pass values to setupWindow which is called from inside the constructor, also you havent specified names for ur arguments in setupWindow, you just declared the type
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1