JAVA创建一个为员工加薪的类 , 自己做了一点但是方法使用不了求指导前几周回答过类似的问题,, 参考代码如下
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编写程序实现输入员工工资,获得员工的平均工资,要求使用象数组类型的一java为员工加薪的代码:将员工姓名、工资封装成一个对象
public class Staff {
private String name;
private int salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public Staff(String name, int salary) {
super();
this.name = name;
this.salary = salary;
}
}
二:初始化一个数组java为员工加薪的代码,算平均工资
public class Average {
public static void main(String[] args) {
Staff staffs[] = {new Staff("zhangsan", 1000), new Staff("lisi", 1100), new Staff("wangwu", 1200)};
int sum= 0;
for(Staff staff : staffs) {
sum = sum + staff.getSalary();
}
System.out.println("员工人数:" + staffs.length + " 总工资:" + sum + " 平均工资:" + sum / staffs.length);
}
}
求java代码public class Salary {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入员工姓名: ");
String name = scanner.next();
System.out.print("请输入员工工龄: ");
int workAge = scanner.nextInt();
int baseSalary = 3000;
if (workAge = 0workAge1) {
baseSalary += 200;
} else if (workAge = 1workAge3) {
baseSalary += 500;
} else if (workAge = 3workAge5) {
baseSalary += 1000;
} else if (workAge = 5workAge10) {
baseSalary += 2500;
} else if (workAge = 10workAge15) {
baseSalary += 5000;
}
System.out.println("员工" + name + "java为员工加薪的代码的工龄为" + workAge + ", 工资为" + baseSalary + "元.");
}
}
java 编程 计算工人工资,JAVA计算工人工资,参考例子如下:
import java.util.Scanner;
public class Demo00 {
//定义一个三维数组,用于记录每个部门、分支、绩效工资
private static final float[][][] SALARY_OF_PER_HOUR = {
推荐阅读
- 斗鱼直播节暂停,斗鱼直播暂停算时间吗
- ChatGPT的负面影响,ChatGPT的负面影响
- chatGPT机器人的功能,ctu 机器人
- 武威主播直播,武威电视台直播
- php查看大数据很慢 php查看大数据很慢怎么回事
- 做电商如何入门工作,小白做电商如何入门
- 群星cpu什么梗的简单介绍
- java写c代码 编写java代码
- 俄罗斯模拟打航母游戏,模拟航母打航母