java 编程 计算工人工资,

2024-11-23 12:22:19
推荐回答(4个)
回答1:

JAVA计算工人工资,参考例子如下:
import java.util.Scanner;
public class Demo00 {
//定义一个三维数组,用于记录每个部门、分支、绩效工资
private static final float[][][] SALARY_OF_PER_HOUR = {
{{10.75f,12.50f,14.50f},{11.75f,14.50f,17.50f}},
{{13.00f,16.00f,18.50f},{15.00f,18.50f,22.00f}},
{{16.75f,18.50f,20.50f},{19.25f,25.00f,30.00f}}
};

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//输入姓名
System.out.println("请输入姓名:");
String name = sc.nextLine();

//输入部门并验证
System.out.println("请输入部门: A,B,C");
char dept = sc.nextLine().charAt(0);
if(dept<'A'||dept>'C')
{
System.out.println("输入有误,系统将退出");
System.exit(0);
}

//输入分支机构并验证
System.out.println("请输入分支机构: 1,2");
char div = sc.nextLine().charAt(0);
if(div<'1'||div>'2')
{
System.out.println("输入有误,系统将退出");
System.exit(0);
}

//输入薪绩表并验证
System.out.println("请输入薪绩表: a,b,c");
char sal = sc.nextLine().charAt(0);
if(sal<'a'||sal>'c')
{
System.out.println("输入有误,系统将退出");
System.exit(0);
}

//输入小时数
System.out.println("请输入本周工作时间(整小时数):");
int hours = sc.nextInt();

float salary = 0;
//每个小时的薪水
float salaryPerHour = SALARY_OF_PER_HOUR[dept-'A'][div-'1'][sal-'a'];

//分别计算40小时内和超过40小时的薪水
if(hours<=40)
{
salary += salaryPerHour*hours;
}
else
{
salary += salaryPerHour*hours+(hours-40)*1.5*salaryPerHour;
}
//输出结果
System.out.println("姓名:\t"+name+"\n部门:\t"+dept+"\n分支机构:\t"+div
+"\n薪绩表:\t"+sal+"\n工作时间:\t"+hours+"\n薪水:\t"+salary);

}
}
//Best wishes!

回答2:

用java设计一个员工类,可以计算工资个人所得税
题目内容
设计一个员工类。该员工具有下列私有属性:编号,姓名,基本工资,奖金 提供有参构造函数:Employee(Strng ID,String name), 提供上述私有属性的读写函数.
提供计算个人所得税的方法:
工资个税的计算公式为:应纳税额=(工资薪金所得 -“五险一金”-扣除数)×适用税率-速算扣除数
自己在实际代码中对上述问题做了一些改进
具体代码与解释
[java]
package Two;
/**
* @author Kun Sun
* @Date: 2013.10.15
*/
public class Employee { // 雇员类
private String ID; // ID
private String name; // 姓名
private int salary; // 工资薪金所得
private int insureHome; // “五险一金”数额
private int deduct; // 扣除数额

Employee(){

}

Employee(String ID,String name){ // 带参数的构造方法
this.ID = ID;
this.name = name;
}

Employee(String ID,String name,int salary,int insureHome,int deduct){ // 带参数的构造方法
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(){ // 个人所得税具体计算
double sefValue;
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);
}
}


[java]
package Two;
/**
* @author Kun Sun
* @Date: 2013.10.15
*/
public class MainClass { // 用于测试雇员类

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("第一种调用方法:");
Employee emp = new Employee("1001","Sun");
emp.setSalary(12345);
emp.setInsureHome(890);
emp.setDeduct(55);
System.out.println("编号为"+emp.getID()+",姓名是"+emp.getName()+" 的应纳税额是:");
emp.selfValue();

System.out.println("------------------------\n第二种调用方法:");
Employee emp2 = new Employee("1001","Sun",12345,890,55);
System.out.println("编号为"+emp2.getID()+",姓名是"+emp2.getName()+" 的应纳税额是:");
emp2.selfValue();

System.out.println("------------------------\n第二种调用方法:");
Employee emp3 = new Employee();
emp3.setID("1001");
emp3.setName("Sun");
emp3.setSalary(12345);
emp3.setInsureHome(890);
emp3.setDeduct(55);
System.out.println("编号为"+emp3.getID()+",姓名是"+emp3.getName()+" 的应纳税额是:");
emp3.selfValue();
}
}

回答3:

那是根据基本工资计算支付工资。代码4的地方不要写,因为是给子类覆盖的抽象方法。

要写的是代码1、代码2、代码3

回答4:

for(int i=0;i    salaries += this[i].earnings();
}