Java case 12: Graduate student salary management system

Idea:

/*
Graduate student salary management system

In school, students need to pay tuition every month, and teachers will pay salaries every month
Working graduate students are both students and teachers and need to pay both tuition and salary.
Write a program to count the income and tuition fees of working graduate students
If the income minus tuition is less than 2,000 yuan, the message "provide a loan (loan required)" is output.
Implemented with interface

1. Define two interfaces,
Declare two methods in the StudentManageInterface interface:
getFee() and setFee() are used to set and obtain student tuition fees;
Declare two methods in the TeacherManageInterface interface:
getPay() and setPay() are used to set and get the teacher's salary;

2. Define the main class Graduate and implement the StudentManageInterface and TeacherManageInterface interfaces respectively.

3. Define the member variables and constructor of the Graduate class

4. Give the implementation of four interface methods

5. Give a method of whether you need a loan,
Calculate the annual income and tuition fees in it, and output the information about whether a loan is needed

6. Create a postgraduate object named "Xia Xiqing" in the main() method,
Call the method that calculates whether a loan is needed

Code:

Code structure:

Test class:

package base.base012;

/*
研究生薪资管理系统

学校中,学生每个月需要缴纳学费,老师每个月会发放工资
在职研究生既是学生又是老师,既需要缴纳学费又有工资
编写程序统计在职研究生的收入与学费
如果收入减去学费不足2000元,则输出“provide a loan(需要贷款)”信息
用接口实现

1.定义两个接口,
在StudentManageInterface接口中声明两个方法:
getFee()和setFee()用于设置和获取学生的学费;
在TeacherManageInterface接口中声明两个方法:
getPay()和setPay()用于设置和获取教师的工资;

2.定义主类Graduate,分别实现StudentManageInterface和TeacherManageInterface接口

3.定义Graduate类的成员变量和构造方法

4.给出四个接口方法的实现

5.给出一个是否需要贷款的方法,
在里面统计年收入和学费,并输出是否需要贷款的信息

6.在main()方法中创建一个姓名为“夏习清”的研究生对象,
调用计算是否需要贷款的方法


 */

public class Test12 {
    public static void main(String[] args) {
        Graduate g1 = new Graduate("夏习清",25,"男",50000,20000);

        if(g1.getPay()*12 - g1.getFee()*12 <2000){
            System.out.println("需要贷款");
        }else {
            System.out.println("不需要贷款");
        }
    }


}
TeacherManageInterface interface:
package base.base012;

/*
在TeacherManageInterface接口中声明两个方法:
getPay()和setPay()用于设置和获取教师的工资;
 */

public interface TeacherManageInterface {

    public abstract void setPay(double pay);
    public abstract double getPay();

}
StudentManageInterface interface:
package base.base012;

/*
在StudentManageInterface接口中声明两个方法:
getFee()和setFee()用于设置和获取学生的学费;
 */

public interface StudentManageInterface {

    public abstract void setFee(double fee);
    public abstract double getFee();
}
Graduate category:
package base.base012;

/*
2.定义主类Graduate,分别实现StudentManageInterface和TeacherManageInterface接口

3.定义Graduate类的成员变量和构造方法

4.给出四个接口方法的实现

5.给出一个是否需要贷款的方法,
在里面统计年收入和学费,并输出是否需要贷款的信息
 */

public class Graduate implements StudentManageInterface,TeacherManageInterface {

    private String name;
    private int age;
    private String sex;
    private double pay;
    private  double fee;

    public Graduate(String name, int age, String sex, double pay, double fee) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.pay = pay;
        this.fee = fee;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public double getPay() {
        return pay;
    }

    @Override
    public void setPay(double pay) {
        this.pay = pay;
    }

    @Override
    public double getFee() {
        return fee;
    }

    @Override
    public void setFee(double fee) {
        this.fee = fee;
    }
}

Guess you like

Origin blog.csdn.net/weixin_54446335/article/details/131802282