做网站用什么软件做百度网页版链接地址
1.编写一个Java方法,接受一个整数数组作为参数,返回该数组中工资高于平均工资的员工数量。假设数组中的每个元素都代表一个员工的工资。
2.设计一个Java方法,接受一个字符串数组和一个关键字作为参数,返回包含该关键字的姓名的员工数量。假设字符串数组中的每个元素都代表一个员工的姓名。
3.编写一个Java方法,接受一个整数数组和一个阈值作为参数,返回超过该阈值的员工数量。假设数组中的每个元素都代表一个员工的年龄。
4.创建一个Java方法,接受一个整数数组和一个工作年限作为参数,返回该工作年限内的员工数量。假设数组中的每个元素都代表一个员工的工作年限。
5.设计一个Java方法,接受一个字符串数组和一个部门名称作为参数,返回该部门的员工数量。假设字符串数组中的每个元素都代表一个员工的部门。
参考代码
package com.hr.work;/*** 类的说明:* 编写一个Java方法,接受一个整数数组作为参数,返回该数组中工资高于平均工资的员工数量。假设数组中的每个元素都代表一个员工的工资。* <p>* 设计一个Java方法,接受一个字符串数组和一个关键字作为参数,返回包含该关键字的姓名的员工数量。假设字符串数组中的每个元素都代表一个员工的姓名。* <p>* 编写一个Java方法,接受一个整数数组和一个阈值作为参数,返回超过该阈值的员工数量。假设数组中的每个元素都代表一个员工的年龄。* <p>* 创建一个Java方法,接受一个整数数组和一个工作年限作为参数,返回该工作年限内的员工数量。假设数组中的每个元素都代表一个员工的工作年限。* <p>* 设计一个Java方法,接受一个字符串数组和一个部门名称作为参数,返回该部门的员工数量。假设字符串数组中的每个元素都代表一个员工的部门。* 格言:认认真真敲代码** @author 汤老师* @date 2024/3/29 15:59*/
public class HRSystem {/*** 1.返回工资高于平均工资的员工数量的方法** @param salaries* @return*/public static int countAboveAverageSalary(int[] salaries) {int total = 0;for (int salary : salaries) {total += salary;}double average = (double) total / salaries.length;int count = 0;for (int salary : salaries) {if (salary > average) {count++;}}return count;}/*** 2.返回包含指定关键字的姓名的员工数量的方法** @param names* @param keyword* @return*/public static int countEmployeesWithKeyword(String[] names, String keyword) {int count = 0;for (String name : names) {if (name.contains(keyword)) {count++;}}return count;}/*** 3.返回超过指定年龄阈值的员工数量的方法** @param ages* @param threshold* @return*/public static int countEmployeesAboveAgeThreshold(int[] ages, int threshold) {int count = 0;for (int age : ages) {if (age > threshold) {count++;}}return count;}/*** 4.返回在指定工作年限内的员工数量的方法** @param workYears* @param years* @return*/public static int countEmployeesWithinYears(int[] workYears, int years) {int count = 0;for (int workYear : workYears) {if (workYear <= years) {count++;}}return count;}/*** 返回指定部门的员工数量的方法** @param departments* @param targetDepartment* @return*/public static int countEmployeesInDepartment(String[] departments, String targetDepartment) {int count = 0;for (String department : departments) {if (department.equals(targetDepartment)) {count++;}}return count;}public static void main(String[] args) {// 测试数据int[] 工资 = {3000, 4000, 5000, 6000, 7000};String[] 姓名 = {"张三", "李四", "王五", "赵六", "钱七"};int[] 年龄 = {25, 30, 35, 40, 45};int[] 工作年限 = {2, 3, 5, 7, 10};String[] 部门 = {"人力资源", "财务", "人力资源", "技术", "人力资源"};// 调用并测试每个方法System.out.println("工资高于平均工资的员工数量: " + HRSystem.countAboveAverageSalary(工资));System.out.println("姓名中包含关键字的员工数量: " + HRSystem.countEmployeesWithKeyword(姓名, "张"));System.out.println("年龄超过阈值的员工数量: " + HRSystem.countEmployeesAboveAgeThreshold(年龄, 35));System.out.println("在指定工作年限内的员工数量: " + HRSystem.countEmployeesWithinYears(工作年限, 5));System.out.println("在人力资源部门的员工数量: " + HRSystem.countEmployeesInDepartment(部门, "人力资源"));}}
参考二
人力资源管理系统 人力资源管理系统 |
参考代码
package com.hr.work;import java.util.Scanner;/*** 类的说明:* 格言:认认真真敲代码** @author 汤老师* @date 2024/3/29 17:04*/
public class HRSystemTest {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int choice;String[] names = {"张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十", "郑十一", "冯十二"};int[] salaries = {3000, 4000, 5000, 6000, 7000, 3500, 4500, 5500, 6500, 7500};int[] ages = {25, 30, 35, 40, 45, 27, 32, 37, 42, 47};int[] workYears = {2, 3, 5, 7, 10, 2, 4, 6, 8, 10};String[] departments = {"人力资源", "财务", "人力资源", "技术", "人力资源", "技术", "人力资源", "财务", "技术", "人力资源"};// 菜单选择do {System.out.println("人力资源管理系统");System.out.println("1. 显示所有员工信息");System.out.println("2. 计算工资高于平均工资的员工数量");System.out.println("3. 计算姓名中包含指定关键字的员工数量");System.out.println("4. 计算年龄超过阈值的员工数量");System.out.println("5. 计算在指定工作年限内的员工数量");System.out.println("6. 计算在指定部门的员工数量");System.out.println("0. 退出系统");System.out.print("请选择操作:");choice = scanner.nextInt();switch (choice) {case 1:displayAllEmployees(names, salaries, ages, workYears, departments);break;case 2:System.out.println("工资高于平均工资的员工数量: " + HRSystem.countAboveAverageSalary(salaries));break;case 3:System.out.println("请输入要搜索的关键字:");String keyword = scanner.next();System.out.println("姓名中包含关键字的员工数量: " + HRSystem.countEmployeesWithKeyword(names, keyword));break;case 4:System.out.println("请输入年龄阈值:");int ageThreshold = scanner.nextInt();System.out.println("年龄超过阈值的员工数量: " + HRSystem.countEmployeesAboveAgeThreshold(ages, ageThreshold));break;case 5:System.out.println("请输入工作年限阈值:");int years = scanner.nextInt();System.out.println("在指定工作年限内的员工数量: " + HRSystem.countEmployeesWithinYears(workYears, years));break;case 6:System.out.println("请输入要搜索的部门名称:");String departmentKeyword = scanner.next();System.out.println("在指定部门的员工数量: " + HRSystem.countEmployeesInDepartment(departments, departmentKeyword));break;case 0:System.out.println("感谢使用人力资源管理系统,再见!");break;default:System.out.println("请选择有效的操作!");break;}} while (choice != 0);scanner.close();}private static void displayAllEmployees(String[] names, int[] salaries, int[] ages, int[] workYears, String[] departments) {System.out.println("所有员工信息:");System.out.println("姓名\t工资\t年龄\t工作年限\t部门");for (int i = 0; i < names.length; i++) {System.out.println(names[i] + "\t" + salaries[i] + "\t" + ages[i] + "\t" + workYears[i] + "\t\t" + departments[i]);}System.out.println();}private static void testAboveAverageSalary() {int[] salaries = {3000, 4000, 5000, 6000, 7000};System.out.println("工资高于平均工资的员工数量: " + HRSystem.countAboveAverageSalary(salaries));}private static void testEmployeesWithKeyword() {String[] names = {"张三", "李四", "王五", "赵六", "钱七"};System.out.println("姓名中包含关键字的员工数量: " + HRSystem.countEmployeesWithKeyword(names, "张"));}private static void testEmployeesAboveAgeThreshold() {int[] ages = {25, 30, 35, 40, 45};System.out.println("年龄超过阈值的员工数量: " + HRSystem.countEmployeesAboveAgeThreshold(ages, 35));}private static void testEmployeesWithinYears() {int[] workYears = {2, 3, 5, 7, 10};System.out.println("在指定工作年限内的员工数量: " + HRSystem.countEmployeesWithinYears(workYears, 5));}private static void testEmployeesInDepartment() {String[] departments = {"人力资源", "财务", "人力资源", "技术", "人力资源"};System.out.println("在人力资源部门的员工数量: " + HRSystem.countEmployeesInDepartment(departments, "人力资源"));}
}