美文网首页
20-案例分析二(Employee)

20-案例分析二(Employee)

作者: c88bc9f9d088 | 来源:发表于2020-10-29 14:13 被阅读0次

    案例分析二:
        编写并测试一个代表员工的Employee类,地址信息由编号、姓名、基本薪水、薪水增长率,还包括计算薪水增长额及计算增长后的工资总额的操作方法。
        这个程序的功能已经超过了简单Java类的定义范畴,因为简单Java类里面不需要涉及到复杂的计算逻辑,但是设计的思考是应该从简单Java类开始。

    class Employee{
        private long empno;
        private String ename;
        private double salary;
        private double rate;
        
        public Employee() {} //无参构造方法 必须有
        public Employee(long empno,String ename,double salary,double rate) {
            this.empno = empno;
            this.ename = ename;
            this.salary = salary;
            this.rate = rate;
        }
        public double salaryIncValue() {
            return this.salary * this.rate;
        }
        public double salaryIncResult() {
            this.salary = this.salary * (1 + this.rate);
            return this.salary;
        }
        public String getInfo() {
            return "编号:" + this.empno + "、姓名:"+ this.ename + "、基本薪水:" + this.salary + "、薪水增长率:" + this.rate;
        }
        public void setEmpno(long empno) {
            this.empno = empno;
        }
        public void setEname(String ename) {
            this.ename = ename;
        }
        public void setSalary(double salary) {
            this.salary = salary;
        }
        public void setRate(double rate) {
            this.rate = rate;
        }
        
        public long getEmpno() {
            return this.empno;
        }
        public String getEname() {
            return this.ename;
        }
        public double getSalary() {
            return this.salary;
        }
        public double getRate() {
            return this.rate;
        }
    }
    public class JavaDemo{
        public static void main(String args[]){
            Employee emp = new Employee(7369L,"史密斯",3000.0,0.3);
            System.out.println(emp.getInfo());
            System.out.println("工资调整额度:" + emp.salaryIncValue());
            System.out.println("上调后的工资:" + emp.salaryIncResult());
            System.out.println(emp.getInfo());
            
        }   
    }
    

    相关文章

      网友评论

          本文标题:20-案例分析二(Employee)

          本文链接:https://www.haomeiwen.com/subject/nhbkvktx.html