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
前几周回答过类似的问题,, 参考代码如下
class Employee {
private String name;
private double salary;
//构造方法
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
public String toString() {
return "姓名:" + name + "\t工资:" + salary;
}
public void raiseSalary(double per) {//加薪的方法
this.salary = salary + salary * per;
}
//属性的 set get方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
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("张三", 2000);
Employee e2 = new Employee("李四", 3000);
Employee e3 = new Employee("王五", 4000);
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);
}
}
输出
姓名:张三 工资:2000.0
姓名:李四 工资:3000.0
姓名:王五 工资:4000.0
==============加薪7%===============
姓名:张三 工资:2140.0
姓名:李四 工资:3210.0
姓名:王五 工资:4280.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!