用java写加薪代码计算 java加班
求java代码
public class Salary {
创新互联2013年至今,是专业互联网技术服务公司,拥有项目成都网站建设、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元东至做网站,已为上家服务,为东至各地企业和个人服务,联系电话:18982081108
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 = 0 workAge 1) {
baseSalary += 200;
} else if (workAge = 1 workAge 3) {
baseSalary += 500;
} else if (workAge = 3 workAge 5) {
baseSalary += 1000;
} else if (workAge = 5 workAge 10) {
baseSalary += 2500;
} else if (workAge = 10 workAge 15) {
baseSalary += 5000;
}
System.out.println("员工" + name + "的工龄为" + workAge + ", 工资为" + baseSalary + "元.");
}
}
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编写一个为员工加薪的类(类与对象)
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 编程 计算工人工资,
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!
新闻名称:用java写加薪代码计算 java加班
分享URL:http://ybzwz.com/article/doiejdj.html