JAVA——附加作业1——统计员工数
生活随笔
收集整理的這篇文章主要介紹了
JAVA——附加作业1——统计员工数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
實驗內容:通過給定的員工列表,顯示工號不重復的員工信息。
創建工程并配置環境:
1)工程名:SE_JAVA_EXP_E01。
2)創建包,取名:cn.com.java.experiment。
3)在包cn.com.java.experiment下創建員工實體類,一個員工的完整數據包括工號、姓名、部門、薪水:Employee。
4)在包cn.com.java.experiment下創建主類:MainClass。
編號 工號 姓名 薪水 部門
1 10001 小王 5000.0f 銷售部
2 10002 小趙 6500.0f 銷售部
3 10001 Alan 15000.0f 研發部
代碼
Employee
Mainclass
package cn.com.java.experiment;public class MainClass {public static boolean isRepeat(int n,Employee[] employees) {Employee emp = employees[n];for(int i = 0;i < employees.length; i++) if(emp != employees[i] && emp.equals(employees[i]) == true) return false;return true;}public static void main(String argv[]) { Employee[] employees = new Employee[3];employees[0] = new Employee("10001","小王","銷售部",5000.0);employees[1] = new Employee("10002","小趙","銷售部",6500.0);employees[2] = new Employee("10001","Alan","研發部",15000.0);for(int i=0;i<employees.length;i++){if(isRepeat(i,employees)==true) System.out.println(employees[i].toString());}} }截圖
總結
以上是生活随笔為你收集整理的JAVA——附加作业1——统计员工数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《大数据》2015年第2期“专题”——关
- 下一篇: SQL中的三大常用字符