java实现工资管理简单程序
作者:飘若归客 发布时间:2021-12-29 22:40:58
标签:java,工资管理
本文为大家分享了java实现工资管理简单程序的具体代码,供大家参考,具体内容如下
程序总体说明(ReadMe):
总体分为四部分:
管理程序(staffmanagment.java):
在这里面使用了arraylist泛型来存放数据
博主正在想办法把数据放进mysql,这样读取会更方便,而且数据不会消失
当然(也可以把数据存入txt文件)
import java.util.ArrayList;
//员工管理
public class staffmanagement {
? ? ArrayList al = null;//员工信息在这里面建立
? ? public staffmanagement()
? ? {
? ? ? ? al = new ArrayList();
? ? }
? ? //成员方法
? ? //添加新员工
? ? public void addstaff(staff staff)
? ? {
? ? ? ? al.add(staff);
? ? }
? ? //根据工号查询员工的信息
? ? public void showInfo(String no)
? ? {
? ? ? ? int flag = 0;
? ? ? ? for(int i=0; i<al.size(); i++)
? ? ? ? {
? ? ? ? ? ? staff staff= (staff)al.get(i);
? ? ? ? ? ? if(staff.getNo().equals(no))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? flag = 1;
? ? ? ? ? ? ? ? System.out.println("员工"+(i+1)+"的信息是:");
? ? ? ? ? ? ? ? System.out.print("姓名:"+staff.getName());
? ? ? ? ? ? ? ? System.out.print(" ?性别:"+staff.getSex());
? ? ? ? ? ? ? ? System.out.print(" ?年龄:"+staff.getAge());
? ? ? ? ? ? ? ? System.out.print(" ?工号:"+staff.getNo());
? ? ? ? ? ? ? ? System.out.print(" ?薪资:"+staff.getSalary());
? ? ? ? ? ? ? ? System.out.print(" ?工作:");
? ? ? ? ? ? ? ? if(staff.getWork() == 1) System.out.println("common staff");
? ? ? ? ? ? ? ? else if(staff.getWork() == 2) System.out.println("common manager");
? ? ? ? ? ? ? ? else if(staff.getWork() == 3) System.out.println("head manager");
? ? ? ? ? ? ? ? System.out.println(staff);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(flag == 0)
? ? ? ? ? ? System.out.println("该工号不存在");
? ? }
? ? //显示所有员工信息
? ? public void ?showAllInfo()
? ? {
? ? ? ? for(int i=0; i<al.size(); i++)
? ? ? ? {
? ? ? ? ? ? staff staff= (staff)al.get(i);
? ? ? ? ? ? System.out.println("staff"+(i+1)+"的信息是:");
? ? ? ? ? ? System.out.print("姓名:"+staff.getName());
? ? ? ? ? ? System.out.print(" ?性别:"+staff.getSex());
? ? ? ? ? ? System.out.print(" ?年龄:"+staff.getAge());
? ? ? ? ? ? System.out.print(" ?工号:"+staff.getNo());
? ? ? ? ? ? System.out.print(" ?薪资:"+staff.getSalary());
? ? ? ? ? ? System.out.print(" ?工作:");
? ? ? ? ? ? if(staff.getWork() == 1) System.out.println("common staff");
? ? ? ? ? ? else if(staff.getWork() == 2) System.out.println("common manager");
? ? ? ? ? ? else if(staff.getWork() == 3) System.out.println("head manager");
? ? ? ? ? ? System.out.println(staff);
? ? ? ? }
? ? }
? ? //修改员工的薪水
? ? public void ?modifySal(String no, double sal) //员工工号 ? 最新的薪资
? ? {
? ? ? ? int flag = 0;
? ? ? ? for(int i=0; i<al.size(); i++)
? ? ? ? {
? ? ? ? ? ? staff staff= (staff)al.get(i);
? ? ? ? ? ? if(staff.getNo().equals(no))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? flag = 1;
? ? ? ? ? ? ? ? staff.setSalary(sal);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(flag == 0)
? ? ? ? ? ? System.out.println("找不到所查工号");
? ? }
? ? //根据工号删除该员工的信息
? ? public void deleteInfo(String no)
? ? {
? ? ? ? int flag = 0;
? ? ? ? for(int i=0; i<al.size(); i++)
? ? ? ? {
? ? ? ? ? ? staff staff= (staff)al.get(i);
? ? ? ? ? ? if(staff.getNo().equals(no))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? flag = 1;
? ? ? ? ? ? ? ? al.remove(i);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(flag == 0)
? ? ? ? ? ? System.out.println("找不到所查工号");
? ? }
? ? //统计当前公司的三个水平工资线
? ? public void calSalary() {
? ? ? ? if (al.isEmpty()) {
? ? ? ? ? ? System.out.println("the stafflist is empty,please input the staff infomation");
? ? ? ? ? ? System.out.println("please input the No 1 to add the staffinfo");
? ? ? ? } else {
? ? ? ? ? ? double totalSal = 0;
? ? ? ? ? ? double minSal = ((staff) al.get(0)).getSalary();
? ? ? ? ? ? double maxSal = ((staff) al.get(0)).getSalary();
? ? ? ? ? ? for (int i = 0; i < al.size(); i++) {
? ? ? ? ? ? ? ? staff staff = (staff) al.get(i);
? ? ? ? ? ? ? ? totalSal += staff.getSalary();
? ? ? ? ? ? ? ? if (minSal > staff.getSalary()) {
? ? ? ? ? ? ? ? ? ? minSal = staff.getSalary();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (maxSal < staff.getSalary()) {
? ? ? ? ? ? ? ? ? ? maxSal = staff.getSalary();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(al.size() + "个人的平均薪资为:" + totalSal / al.size());
? ? ? ? ? ? System.out.println(al.size() + "个人的最低薪资为:" + minSal);
? ? ? ? ? ? System.out.println(al.size() + "个人的最高薪资为:" + maxSal);
? ? ? ? }
? ? }
}
界面模块(SalarySystem.java)
对不同员工的工资最低进行了限制,毕竟法律规定了不能给太低
年龄也是(至少得成年吧——你懂的)
职位还可以安排更多
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
* @antuor:jeffw
* 员工界面为博主清风追梦的写法
* 清风大大的blogs:http://www.cnblogs.com/qingfengzhuimeng/p/6509965.html
* io输入输出
* 在员工的类别上加入员工的职业区分别建立不同的类
* 程序使用英语+中文方式= =顺便练习英语
*/
public class SalarySystem {
? ? public static void main(String[] args) throws IOException //使用bufferreader读取更加的安全,当读取不到的返回错误抛出
? ? {
? ? ? ? staffmanagement sys = new staffmanagement();
? ? ? ? InputStreamReader isr = new InputStreamReader(System.in);//输入流为系统,也可以从文本读取,一次读取一个字符
? ? ? ? BufferedReader br = new BufferedReader(isr);//读取,对输入流的封装,可以读取一行,一个字符或者是一个数字
? ? ? ? //这里以isr读取到的传给br
? ? ? ? while(true)
? ? ? ? {
? ? ? ? ? ? //简易菜单
? ? ? ? ? ? System.out.println("简单管理菜单" );
? ? ? ? ? ? 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("7.查看具体工作名称");
? ? ? ? ? ? System.out.println("8.最低工资说明");
? ? ? ? ? ? System.out.println("9.清屏");
? ? ? ? ? ? System.out.println("0.退出");
? ? ? ? ? ? System.out.println("---------------------------------------");
? ? ? ? ? ? System.out.println("请选择序号:");
? ? ? ? ? ? String no = br.readLine();
? ? ? ? ? ? if(no.equals("1")) {
? ? ? ? ? ? ? ? System.out.println("添加新员工:");
? ? ? ? ? ? ? ? System.out.println("请输入姓名:");
? ? ? ? ? ? ? ? String name = br.readLine();
? ? ? ? ? ? ? ? System.out.println("请输入性别(男or女):");
? ? ? ? ? ? ? ? String sex = br.readLine();
? ? ? ? ? ? ? ? System.out.println("请输入工作:");
? ? ? ? ? ? ? ? System.out.println("目前共有三种职位:\n" +
? ? ? ? ? ? ? ? ? ? ? ? "1.common_staff\n" +
? ? ? ? ? ? ? ? ? ? ? ? "2.common_manager\n" +
? ? ? ? ? ? ? ? ? ? ? ? "3.head_manager");
? ? ? ? ? ? ? ? System.out.println("please input the work id:");
? ? ? ? ? ? ? ? int work = Integer.parseInt(br.readLine());
? ? ? ? ? ? ? ? System.out.println("请输入年龄:");
? ? ? ? ? ? ? ? Scanner sc = new Scanner(System.in);
? ? ? ? ? ? ? ? int age = sc.nextInt();
? ? ? ? ? ? ? ? if( age < 18 ){
? ? ? ? ? ? ? ? ? ? System.out.println("the age is too small,please input again");
? ? ? ? ? ? ? ? ? ? sc = new Scanner(System.in);
? ? ? ? ? ? ? ? ? ? age = sc.nextInt();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? System.out.println("请输入工号:");
? ? ? ? ? ? ? ? String staffNo = br.readLine();
? ? ? ? ? ? ? ? System.out.println("请输入工资:");
? ? ? ? ? ? ? ? double salary = Double.parseDouble(br.readLine());
? ? ? ? ? ? ? ? if( work == 1 ) {
? ? ? ? ? ? ? ? ? ? while (salary < 2000) {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("the common staff's salary is too low");
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("请重新输入");
? ? ? ? ? ? ? ? ? ? ? ? salary = Double.parseDouble(br.readLine());
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else if( work == 2 ) {
? ? ? ? ? ? ? ? ? ? while (salary < 5000) {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("the manager's salary is too low");
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("请重新输入");
? ? ? ? ? ? ? ? ? ? ? ? salary = Double.parseDouble(br.readLine());
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else if( work == 3 ) {
? ? ? ? ? ? ? ? ? ? while (salary < 8000) {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("the head manager's salary is too low");
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("请重新输入");
? ? ? ? ? ? ? ? ? ? ? ? salary = Double.parseDouble(br.readLine());
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? staff staff = null;
? ? ? ? ? ? ? ? if (work == 1) {
? ? ? ? ? ? ? ? ? ? staff = new staff(name, sex, age, staffNo, salary, work);
? ? ? ? ? ? ? ? } else if(work == 2){
? ? ? ? ? ? ? ? ? ? staff = new manager(name, sex, age, staffNo, salary, work);
? ? ? ? ? ? ? ? }else if(work == 3 ) {
? ? ? ? ? ? ? ? ? ? staff = new manager(name, sex, age, staffNo, salary, work);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? sys.addstaff(staff);
? ? ? ? ? ? }else if(no.equals("2")){
? ? ? ? ? ? ? ? System.out.println("请输入员工号:");
? ? ? ? ? ? ? ? String staffNo = br.readLine();
? ? ? ? ? ? ? ? sys.showInfo(staffNo);
? ? ? ? ? ? }else if(no.equals("3")){
? ? ? ? ? ? ? ? System.out.println("显示所有员工信息:");
? ? ? ? ? ? ? ? sys.showAllInfo();
? ? ? ? ? ? }else if(no.equals("4")){
? ? ? ? ? ? ? ? System.out.println("修改员工的薪水:");
? ? ? ? ? ? ? ? System.out.println("输入员工工号:");
? ? ? ? ? ? ? ? String staffNo = br.readLine();//接收输入的工号
? ? ? ? ? ? ? ? System.out.println("修改后的员工工资:");
? ? ? ? ? ? ? ? String sal = br.readLine();
? ? ? ? ? ? ? ? double salary = Double.parseDouble(sal);
? ? ? ? ? ? ? ? sys.modifySal(staffNo, salary);
? ? ? ? ? ? }else if(no.equals("5")){
? ? ? ? ? ? ? ? System.out.println("根据工号删除该员工的信息:");
? ? ? ? ? ? ? ? System.out.println("输入员工工号:");
? ? ? ? ? ? ? ? String staffNo = br.readLine();//接收输入的工号
? ? ? ? ? ? ? ? sys.deleteInfo(staffNo);
? ? ? ? ? ? }else if(no.equals("6")){
? ? ? ? ? ? ? ? System.out.println("统计员工的平均工资、最高工资和最低工资:");
? ? ? ? ? ? ? ? sys.calSalary();
? ? ? ? ? ? }else if(no.equals("7")) {
? ? ? ? ? ? ? ? System.out.println("查看具体工作名称:\n" +
? ? ? ? ? ? ? ? ? ? ? ? "序号1为common staff\n" +
? ? ? ? ? ? ? ? ? ? ? ? "序号2为conmmon manager\n" +
? ? ? ? ? ? ? ? ? ? ? ? "序号3为head manger");
? ? ? ? ? ? }else if(no.equals("8")) {
? ? ? ? ? ? ? ? System.out.println("最低工资说明:\n" +
? ? ? ? ? ? ? ? ? ? ? ? "1.common staff 最低工资为2000\n" +
? ? ? ? ? ? ? ? ? ? ? ? "2.conmmon manager 最低工资为5000\n" +
? ? ? ? ? ? ? ? ? ? ? ? "3.head manager 最低工资为8000\n");
? ? ? ? ? ? }else if(no.equals("9")){
? ? ? ? ? ? ? ? int i=0;
? ? ? ? ? ? ? ? while( i < 80) {
? ? ? ? ? ? ? ? ? ? System.out.println("********");
? ? ? ? ? ? ? ? ? ? i++;
? ? ? ? ? ? ? ? }//java因为ide的原因没有提供内置类似c++的方法,所以只能简陋的使用***来清屏了= ?=
? ? ? ? ? ? ? ? System.out.println("如果觉得看着麻烦的话,可以在console里面鼠标右击->clear");
? ? ? ? ? ? }else if(no.equals("0")){
? ? ? ? ? ? ? ? System.exit(0);
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? System.out.println("请输入正确的序号");
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
普通职位模块(staff.java)
所有的员工模块通过此模块进行扩展
//普通员工类
public class staff
{
? ? private String name;
? ? private String sex;
? ? private int age;
? ? private String no;
? ? private double salary;
? ? private int work;
? ? public staff(){}
? ? public staff(String name, String sex, int age, String no, double salary,int work)
? ? {
? ? ? ? this.name = name;
? ? ? ? this.sex = sex;
? ? ? ? this.age = age;
? ? ? ? this.no = no;
? ? ? ? this.salary = salary;
? ? ? ? this.work = work;
? ? }
? ? @Override
? ? public String toString() {
// ? ? ? ?return "this is a common staff\n"
// ? ? ? ? ? ? ? ?+"name:"+name+"\n"
// ? ? ? ? ? ? ? ?+"sex :"+sex+"\n"
// ? ? ? ? ? ? ? ?+"age :"+age+"\n"
// ? ? ? ? ? ? ? ?+"no :"+no+"\n"
// ? ? ? ? ? ? ? ?+"salary :"+salary+"\n"
// ? ? ? ? ? ? ? ?+"work :"+work+"\n";
? ? ? ? return getWork()+" the common staff is working and the salary is "+getSalary()+"\n" +
? ? ? ? ? ? ? ? "his/her workid is 1 and he/she needs handle with the company's common situations";
? ? }
? ? public String getName() {
? ? ? ? return name;
? ? }
? ? public void setName(String name) {
? ? ? ? this.name = name;
? ? }
? ? public String getSex() {
? ? ? ? return sex;
? ? }
? ? public void setSex(String sex) {
? ? ? ? this.sex = sex;
? ? }
? ? public int getAge() {
? ? ? ? return age;
? ? }
? ? public void setAge(int age) {
? ? ? ? this.age = age;
? ? }
? ? public String getNo() {
? ? ? ? return no;
? ? }
? ? public void setNo(String no) {
? ? ? ? this.no = no;
? ? }
? ? public double getSalary() {
? ? ? ? return salary;
? ? }
? ? public void setSalary(double salary) {
? ? ? ? this.salary = salary;
? ? }
? ? public void setWork(int work){
? ? ? ? this.work = work;
? ? }
? ? public ?int getWork(){
? ? ? ? return work;
? ? }
}
扩展职位模块
1.common manager
public class manager extends staff{
? ? public manager(String name, String sex, int age, String no, double salary, int work) {
? ? ? ? setName(name);
? ? ? ? setSalary(salary);
? ? ? ? setAge(age);
? ? ? ? setNo(no);
? ? ? ? setSex(sex);
? ? ? ? setWork(work);
? ? }
? ? public manager(){
? ? ? ? System.out.println("this is a manager");
? ? }
? ? @Override
? ? public String toString() {
? ? ? ? return "the manager is working and the salary is "+getSalary()+"\n" +
? ? ? ? ? ? ? ? "his workid is 3 and he needs handle with the company's emergency situations";
? ? }
}
2.head manager
public class headmanager extends ?manager{
? ? public headmanager(String name, String sex, int age, String no, double salary, int work) {
? ? ? ? setName(name);
? ? ? ? setSalary(salary);
? ? ? ? setAge(age);
? ? ? ? setNo(no);
? ? ? ? setSex(sex);
? ? ? ? setWork(work);
? ? }
? ? public headmanager(){
? ? ? ? System.out.println("this is a headmanager");
? ? ? ? System.out.println("his workid is 3 " +
? ? ? ? ? ? ? ? ? ? "and he needs handle with " +
? ? ? ? ? ? ? ? ? ? "the company's emergency situations");
? ? }
? ? @Override
? ? public String toString() {
? ? ? ? return "the headmanager is working and the salary is "+getSalary()+getSalary()+"\n" +
? ? ? ? ? ? ? ? "his/her workid is 2 and he/she needs hanle whih the compant's main development";
? ? }
}
运行展示
2018.12.15更新:
现在还没有想到怎么用数据库连接,不过新学习了file文件操作模式,现在把这种方式加入到员工管理里面:
以下是增加内容:
else if(no.equals("10")) {
? ? ? ? ? ? ? ? System.out.println("正在读取中,请稍候...");
? ? ? ? ? ? ? ? File file = new File("1.txt");
? ? ? ? ? ? ? ? Scanner input = new Scanner(file);
? ? ? ? ? ? ? ? while(input.hasNext()){
? ? ? ? ? ? ? ? ? ? String name = input.nextLine();
? ? ? ? ? ? ? ? ? ? String sex = input.nextLine();
? ? ? ? ? ? ? ? ? ? int work = input.nextInt();
? ? ? ? ? ? ? ? ? ? int age =input.nextInt();
? ? ? ? ? ? ? ? ? ? input.nextLine();
? ? ? ? ? ? ? ? ? ? String staffNo = input.nextLine();
? ? ? ? ? ? ? ? ? ? double salary = input.nextDouble();
? ? ? ? ? ? ? ? ? ? staff staff = null;
? ? ? ? ? ? ? ? ? ? if (work == 1) {
? ? ? ? ? ? ? ? ? ? ? ? staff = new staff(name, sex, age, staffNo, salary, work);
? ? ? ? ? ? ? ? ? ? } else if(work == 2){
? ? ? ? ? ? ? ? ? ? ? ? staff = new manager(name, sex, age, staffNo, salary, work);
? ? ? ? ? ? ? ? ? ? }else if(work == 3 ) {
? ? ? ? ? ? ? ? ? ? ? ? staff = new manager(name, sex, age, staffNo, salary, work);
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("不存在此职业");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? sys.addstaff(staff);
? ? ? ? ? ? ? ? ? ? System.out.println("导入成功");
? ? ? ? ? ? ? ? }
接下来的想法是把重复的员工去除,想先通过提醒使用者导入员工后,删除原有员工文件,然后在使用者退出前提示导入员工名单进行解决可能出现的员工重复问题
来源:https://blog.csdn.net/sos768/article/details/84797684


猜你喜欢
- 通过下面代码在构造函数中调用方法 SetShadow();即可实现无边框窗体的阴影效果了需要添加命名空间 using System.Runt
- 首先,将json串转为一个JObject对象:JObject jo = (JObject)JsonConvert.DeserializeOb
- 本文实例讲述了Asp.net中C#使用Socket发送和接收TCP数据的方法,分享给大家供大家参考。具体实现方法如下:具体程序代码如下:us
- 多线程内容大致分两部分,其一是异步操作,可通过专用,线程池,Task,Parallel,PLINQ等,而这里又涉及工作线程与IO线程;其二是
- 第一:写Cookies Response.Cookies["UserName"].Value="Guest&q
- 简介最近花了两天时间研究使用Flutter开发一个抖音国际版. 个人感觉使用Flutter开发app快得不要不要的额. 两天就基本可以开发个
- 宏定义与预处理命令预处理阶段:处理宏定义与预处理命令;编译期:检查代码,分析语法、语义等,最后生成.o或.obj文件;链接期:链接所有的.o
- 夏天到了、小雪来给大家降降温话不多说、直接进入主题主要功能模块设计:登录注册、首页信息浏览、选课分类查看、选课详情查看、评论交流、收藏、浏览
- 题目:将一个数组逆序输出。代码:import java.util.*;public class lianxi31 {public stati
- java集合中,list列表应该是我们最常使用的,它有两种常见的实现类:ArrayList和LinkedList。ArrayList底层是数
- 1. 新建项目引入web和security包完整的pom.xml文件如下<?xml version="1.0" e
- 如何接收Post请求Body里的参数ApiPost测试数据{ "list": [
- Selenium 是目前用的最广泛的Web UI 自动化测试框架。 本系列文章,将深入简出来讲解selenium 的用法阅读目录seleni
- Java 中java.io.IOException: Broken pipe认识broken pipepipe是管道的意思,管道里面是数据流
- 一、 Spring Bean 配置方式由 Spring IoC 容器管理的对象称为 Bean,Bean 配置方式有两种:配置文件开发和注解开
- 在Java中对集合进行操作时,有时候需要对类中的equals() 和 hashCode()进行方法重写.IDEA中实现了利用快捷键即可对上述
- 通过zookeeper实现分布式锁1、创建zookeeper的client首先通过CuratorFrameworkFactory创建一个连接
- 访问修饰符都知道是什么,但是在这之前没有深入的去研究和探索,每天都接触的东西应该清楚才可以。最基础的三个访问修饰符:public 、priv
- 现在越来越多手机支持OTG功能,通过OTG可以实现与外接入的U盘等USB设备实现数据传输。 USB OTG(On The Go)作
- 一. 先来一段代码我们先上一段代码:String str1 = new StringBuilder("你好").appe