Interface and class inheritance

Requirements
1) Design two information management interfaces StudentInterface and TeacherInterface. Among them, the StudentInterface interface includes the setFee() method and the getFee() method, which are used to set and obtain the student's tuition, respectively; the TeacherInterface interface includes the setPay() method and the getPay() method, which are used to set and obtain the teacher's salary, respectively.
2) Define a graduate class Graduate, which implements the StudentInterface interface and the TeacherInterface interface. The member variables it defines are name (name), sex (gender), age (age), fee (tuition per semester), pay (monthly salary).
3) Create a graduate student named "zhangsan" and count his annual income and tuition. If the income minus tuition is less than 2,000 yuan, output the information "provide a loan".

Code

// An highlighted block
import java.util.Scanner;
interface StudentInterface{
    
    
	
   public double setFee(double fee);
   public double getFee();
		
}
interface TeacherInterface{
    
    
	public double setPay(double pay);
	public double getPay();

}
public class Graduate implements StudentInterface,TeacherInterface{
    
    
    static String Name;
    static String Sex;
    static int Age;
    static double Fee;
    static double Pay;
    static double total;
    Graduate(String name, String sex,int age, double fee, double pay){
    
    
    	Name=name;
    	Sex=sex;
    	Age=age;
    	Fee=fee;
    	Pay=pay;
    	
    	
    	
    }

	public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub
		double x;
		double y;
		Graduate zhangsan = new Graduate("zhangsan","男",22,0,0);
		Scanner in = new Scanner(System.in);
		System.out.println("请输入您的学费和月收入");
		x=in.nextDouble();
		y=in.nextDouble();
		in.close();
        zhangsan.setFee(x);
        zhangsan.setPay(y);
        zhangsan.total();
       
	}


	@Override
	public double setFee(double fee) {
    
    
		// TODO Auto-generated method stub
		Fee=fee;
		return 0;
	}

	@Override
	public double getFee() {
    
    
		// TODO Auto-generated method stub
		return  Fee;
	}

	@Override
	public  double setPay(double pay) {
    
    
		// TODO Auto-generated method stub
		Pay=pay;
	    return 0;
	}

	@Override
	public double getPay() {
    
    
		// TODO Auto-generated method stub
		return Pay;
	}
	public void total(){
    
    
		
		System.out.println("姓名:" + Name + "\n" + "性别:"+Sex+"\n"+"年收入:" +12*getPay()+"元"+ "\n"+ "学费:"+getFee()+"元"+ "\n");
		System.out.println();
		if(12*getPay()-+getFee()<2000)
			System.out.println("需要贷款");
		else
			System.out.println("不需要贷款");
			
		
	}

	
	}

Guess you like

Origin blog.csdn.net/weixin_43495262/article/details/110098599