Design an employee class in java to calculate Personal Income Tax

Source: Internet
Author: User

Use java to design an employee class that can calculate the Personal Income Tax on wages. 1. The background teacher assigned several java programming questions in the class. This is one of them. 2. design an employee class. The Employee has the following private attributes: number, name, basic salary, and bonus parameters constructor: Employee (Strng ID, String name), which provides the Read and Write Functions for the preceding private attributes. provides the method for calculating Personal Income Tax: the formula for calculating personal income tax is: taxable amount = (wage and salary income-"Five insurances and one gold"-deduction amount) × applicable tax rate-Fast Calculation and deduction I made some improvements to the above problems in the actual code 3. code and explanation [java] <span style = "font-family: SimSun; font-size: 14px"> package Two;/*** @ author Kun Sun * @ Date: 2013.10.15 */public class Employee {// Employee class private String ID; // ID private String name; // name private int salary; // salary income private int insureHome; // "Five insurances and one gold" amount private int deduct; // deduct the amount of Employee () {} Employee (String ID, String name) {// construction method with parameters this. ID = ID; this. name = name;} Employee (String ID, String name, int salary, int insureHome, int deduct) {// constructor with parameters this. ID = ID; this. name = name; this. salary = salary; this. insureHome = insureHome; this. deduct = deduct;} public String getID () {return ID;} public String getName () {return name;} public int getSalary () {return salary;} public int getInsureHome () {return insureHome;} public int getDeduct () {return deduct;} public void setID (String iD) {ID = iD;} public void setName (String name) {this. name = name;} public void setSalary (int salary) {this. salary = salary;} public void setInsureHome (int insureHome) {this. insureHome = insureHome;} public void setDeduct (int deduct) {this. deduct = deduct;} public void selfValue () {// calculate the double sefValue for personal income tax; if (salary> = 0 & salary <1500) {sefValue = (double) (salary-insureHome-deduct) * 0.03-0;} else if (salary >=1500 & salary <4500) {sefValue = (double) (salary-insureHome-deduct) * 0.1-105;} else if (salary >=4500 & salary <9000) {sefValue = (double) (salary-insureHome-deduct) * 0.2-555 ;} else if (salary> = 9000 & salary <35000) {sefValue = (double) (salary-insureHome-deduct) * 0.25-1005 ;} else if (salary> = 35000 & salary <55000) {sefValue = (double) (salary-insureHome-deduct) * 0.30-2755 ;} else if (salary> = 55000 & salary <80000) {sefValue = (double) (salary-insureHome-deduct) * 0.35-5505;} else {sefValue = (double) (salary-insureHome-deduct) * 0.45-13505;} System. out. println (sefValue) ;}</span> [java] <span style = "font-family: SimSun; font-size: 14px"> package Two; /*** @ author Kun Sun * @ Date: 2013.10.15 */public class MainClass {// used to test the employee class/*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stub System. out. println ("Method 1:"); Employee emp = new Employee ("1001", "Sun"); emp. setSalary (1, 12345); emp. setInsureHome (890); emp. setDeduct (55); System. out. println ("number:" + emp. getID () + ", name:" + emp. the tax payable for getName () + "is:"); emp. selfValue (); System. out. println ("------------------------ \ n Method 2:"); Employee emp2 = new Employee ("1001", "Sun", 12345,890, 55); System. out. println ("number:" + emp2.getID () + ", the tax payable for" + emp2.getName () + "is:"); emp2.selfValue (); System. out. println ("---------------------- \ n Method 2:"); Employee emp3 = new Employee (); emp3.setID ("1001"); emp3.setName ("Sun "); emp3.setSalary (12345); emp3.setInsureHome (890); emp3.setDeduct (55); System. out. println ("number:" + emp3.getID () + ", the tax payable for" + emp3.getName () + "is:"); emp3.selfValue ();}} </span> 4. test Run result

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.