扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
class Salary{
成都创新互联公司凭借专业的设计团队扎实的技术支持、优质高效的服务意识和丰厚的资源优势,提供专业的网站策划、成都网站设计、网站建设、网站优化、软件开发、网站改版等服务,在成都10年的网站建设设计经验,为成都近1000家中小型企业策划设计了网站。
private int no;
private String name;
private double deal;
private double tax;
public Salary(int no,String name,double deal,double tax){
this.no=no;
this.name=name;
this.deal=deal;
this.tax=tax;
}
public double count(){
return this.deal-this.tax;
}
public void output(){
System.out.println("工号"+this.no);
System.out.println("姓名"+this.name);
System.out.println("应发工资"+this.deal);
System.out.println("税金"+this.tax);
System.out.println("实发工资"+count());
}
public static void main(String[] args){
Salary a=new Salary(1,"张三",1000,200);
a.output();
Salary b=new Salary(2,"李四",1500,200);
b.output();
}
}
class Employee {
private String name;
private String department;
private double salary;
//构造方法
public Employee(String name, String department, double salary) {
this.name = name;
this.department = department;
this.salary = salary;
}
public String toString() {
return "姓名:" + name + "\t部门:" + department + "\t工资:" + salary;
}
public void raiseSalary(double per) {
this.salary = salary + salary * per;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
public class TestEmployee {//测试类
public static void main(String[] args) {
Employee e1 = new Employee("张三", "技术开发部", 5000);
Employee e2 = new Employee("赵四", "后勤服务部", 3800);
Employee e3 = new Employee("王五", "产品营销部", 6800);
System.out.println(e1 + "\n" + e2 + "\n" + e3);
double per = 0.07;
e1.raiseSalary(per);
e2.raiseSalary(per);
e3.raiseSalary(per);
System.out.println("==============加薪7%===============");
System.out.println(e1 + "\n" + e2 + "\n" + e3);
}
}
输出
姓名:张三 部门:技术开发部 工资:5000.0
姓名:赵四 部门:后勤服务部 工资:3800.0
姓名:王五 部门:产品营销部 工资:6800.0
==============加薪7%===============
姓名:张三 部门:技术开发部 工资:5350.0
姓名:赵四 部门:后勤服务部 工资:4066.0
姓名:王五 部门:产品营销部 工资:7276.0
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!
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流