Payroll Calculator

Take a look!

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 5648 Views - Last Post: 12 September 2009 - 10:49 AM Rate Topic: -----

#16 TheNobleSword  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 05-September 09

Re: Payroll Calculator

Posted 11 September 2009 - 05:38 PM

haha what a newb!

It works perfect!

I do have one question, how do I limit the "double" to 2 decimal places?

Also, for this part

"After you are successful at getting the program to work with one set of data at a time - add a while loop that will make the program stop when the user enters a 'Q' or 'q' as the next employee type."

Would I add somthing like

while ('a' != Q)


Thanks for the help Anton!
Was This Post Helpful? 0
  • +
  • -

#17 TheNobleSword  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 05-September 09

Re: Payroll Calculator

Posted 11 September 2009 - 10:03 PM

I am almost done!

In order to round the currency output to two decimal places I used this code.

DecimalFormat money = new DecimalFormat("0.00");
				"\nEmployee Name:"+ " " +name+
				"\nEmployee Salary:"+ " $" +money.format(salary)+
				"\nGross Earnings:"+ " $" +money.format(grossS)+
				"\nTotal tax deducated:"+ " $" +money.format(taxS)+
				"\nWeekly Pay:"+ " $" +money.format(netS));




I do not know if this is the best way to do this, but it seems to work.

The only thing I need to do now is add the while loop that will disable the program is "q" is entered.

I tried.

while ('a' != 'q')


Thinking, as long as char 'a' does not equal 'q' then the program will run. but it did not work for me.
Was This Post Helpful? 0
  • +
  • -

#18 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: Payroll Calculator

Posted 11 September 2009 - 11:34 PM

Try this out.

import javax.swing.JOptionPane;
import java.util.Scanner;
public class CylinderVolume {

	public static void main(String[] args) {
		char a = ' ';
		while(a != 'q'){
		String type = JOptionPane.showInputDialog("Enter Employee Type: ");
		a = type.toLowerCase().charAt(0);

		String name = JOptionPane.showInputDialog("Enter Employees Name: ");
		


		if (a=='s'){
		String salaryStr = JOptionPane.showInputDialog("Enter Employee Salary: ");
		int salary = Integer.parseInt(salaryStr);

		double grossS= salary*1/52;
		double taxS= grossS*0.18;
		double netS= grossS-taxS;


		JOptionPane.showMessageDialog(null,"Employee type:" +'a'+
				"/nEmployee Name:" +name+
				"/nWeekly pay:" + netS+
				"/nTotal tax deducated:"+taxS);
	   }
	   else if (a=='h'){

		String rateStr = JOptionPane.showInputDialog("Enter Employee Rate: ");
		int rate = Integer.parseInt(rateStr);

		String hoursStr = JOptionPane.showInputDialog("Enter Employee Hours: ");
		int hours = Integer.parseInt(hoursStr);

		double grossH= rate*hours;
		double taxH= rate*hours*0.18;
		double netH= grossH-taxH;

		JOptionPane.showMessageDialog(null,"Employee type:" +'a'+
				"/nEmployee Name:" +name+
				"/nWeekly pay:" + netH+
				"/nTotal tax deducted:"+taxH);
	   }
		}
	   

	}
}


Was This Post Helpful? 0
  • +
  • -

#19 TheNobleSword  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 05-September 09

Re: Payroll Calculator

Posted 12 September 2009 - 01:42 AM

I think I got it! Take a look Anton, you did most of it. Thanks so much, your really took your time to help me, I really appreciate it!

I am sure that there are somethings that still need to be adjust, feel free to point them out!

   
package payrollcalculator;
import javax.swing.JOptionPane;
import java.text.*;

public class PayrollCalculator {

	public static void main(String[] args) {

		char a=' ';
		while (a !='q'){

		DecimalFormat money = new DecimalFormat("0.00");

		//Employee Type
		String type = JOptionPane.showInputDialog("Enter Employee Type: ");
		a = type.toLowerCase().charAt(0);

		//Employee Name
		String name = JOptionPane.showInputDialog("Enter Employees Name: ");
  
		//Salary Employee
		if (a=='s'){
		String salaryStr = JOptionPane.showInputDialog("Enter Employee Salary: ");
		int salary = Integer.parseInt(salaryStr);

		//Salary divided by 52, 18% tax deducted
		double grossS= salary*1/52;
		double taxS= grossS*0.18;
		double netS= grossS-taxS;


		JOptionPane.showMessageDialog(null,
				"Employee type:"+" " +type+
				"\nEmployee Name:"+ " " +name+
				"\nEmployee Salary:"+ " $" +money.format(salary)+
				"\nGross Earnings:"+ " $" +money.format(grossS)+
				"\nTotal tax deducated:"+ " $" +money.format(taxS)+
				"\nWeekly Pay:"+ " $" +money.format(netS));
				
	   }

	   //Temp Employee
	   else if (a=='t'){

		//Hourly Rate
		String TrateStr = JOptionPane.showInputDialog("Enter Employee Rate: ");
		int rateT = Integer.parseInt(TrateStr);
		//Amount of hours worked
		String ThoursStr = JOptionPane.showInputDialog("Enter Employee Hours: ");
		int hoursT = Integer.parseInt(ThoursStr);

		//Rate*Time, No tax deducted
		double grossT= rateT*hoursT;
		double netT= rateT*hoursT;

		

		JOptionPane.showMessageDialog(null,
				"Employee type:"+" "+type+
				"\nEmployee Name:"+ " " +name+
				"\nHourly Rate:"+ " $" +money.format(rateT)+
				"\nHours Worked:"+ " "+hoursT+
				"\nNO TAX DEDUCTED"+
				"\nWeekly Pay:"+ " $" + money.format(netT));
	   }

		//Hourly Employee
		else if (a=='h'){

		//Hourly Rate
		String HrateStr = JOptionPane.showInputDialog("Enter Employee Rate: ");
		int rateH = Integer.parseInt(HrateStr);

		//Amount of hours
		String HhoursStr = JOptionPane.showInputDialog("Enter Employee Hours: ");
		int hoursH = Integer.parseInt(HhoursStr);

		//Rate*Time, 18% tax deducted
		double  grossH= rateH*hoursH;
		double taxH= rateH*hoursH*0.18;
		double netH= grossH-taxH;

		JOptionPane.showMessageDialog(null,
				"Employee type:"+" " +type+
				"\nEmployee Name:"+ " " +name+
				"\nHourly Rate:"+ " $" +money.format(rateH)+
				"\nHours Worked:"+ " "+hoursH+
				"\nGross Earnings:"+ " $"+money.format(grossH)+
				"\nTotal Tax Deducted:"+ " $"+money.format(taxH)+
				"\nWeekly Pay:"+ " $" + money.format(netH));
			}
		}
	}
}



Was This Post Helpful? 0
  • +
  • -

#20 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: Payroll Calculator

Posted 12 September 2009 - 02:09 AM

You are welcome, sir.
Well, the code doesn't seem to have any errors to me, so I guess it's alright.
By the way, I'm really sorry for that quote I made, which you're using as signature right now lol. I meant no offense.
Was This Post Helpful? 0
  • +
  • -

#21 TheNobleSword  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 05-September 09

Re: Payroll Calculator

Posted 12 September 2009 - 10:17 AM

No offense at all, I thought it was funny. I am not afraid to admit that I am a beginner.
Was This Post Helpful? 0
  • +
  • -

#22 TheNobleSword  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 05-September 09

Re: Payroll Calculator

Posted 12 September 2009 - 10:49 AM

double post, oops.

This post has been edited by TheNobleSword: 12 September 2009 - 10:50 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2