1.定义一个抽象类Person,有三个属性:姓名、性别、联系电话,用构造函数对三个属性进行赋初值,定义函数输出三个属性的值;
2.定义一个接口Person_Interface,声明一个常量为薪酬标准(自己设置一个值),声明一个方法计算薪酬(参数为天数)
3.定义一个学生类继承Person类,再增加两个属性:学号和专业,用构造函数对所有属性进行赋初值,并输出学生的所有信息;
4.定义一个教师类继承Person类并实现接口Person_Interface,定义一个工号,定义一个函数对教师的所有属性进行赋初值,并根据输入的天数结算教师薪酬,再定一个函数显示教师的所有信息。
5.定义一个测试类,对教师类和学生类实例化,并赋初值和显示出来。
package chap03;
public abstract class Person {
protected String name;
protected String sex;
protected String contect;
Person(String name1,String sex1,String contect1){
name=name1;
sex=sex1;
contect=contect1;
}
public void display(){
System.out.println("姓名:"+name);
System.out.println("性别:"+sex);
System.out.println("联系方式:"+contect);
}
}
package Impl;
public interface Person_Interface {
public static final double salary=3500.00;
public static final int day=15;
}
package chap03;
public class Student extends Person {
String sno;
String profession;
public Student(String name, String sex, String contect,
String sno1,String profession1) {
super(name, sex, contect);
sno=sno1;
profession=profession1;
// TODO Auto-generated constructor stub
}
public void display(){
System.out.println("学号:"+sno);
System.out.println("专业:"+profession);
System.out.println("姓名:"+name);
System.out.println("性别:"+sex);
System.out.println("联系方式:"+contect);
}
}
import Impl.Person_Interface;
public class Teacher extends Person implements Person_Interface {
String job_number;
public Teacher(String name1, String sex1,
String contect1,String job_number) {
super(name1, sex1, contect1);
this.job_number=job_number;
// TODO Auto-generated constructor stub
}
public void display(){
System.out.println("工号:"+job_number);
System.out.println("姓名:"+name);
System.out.println("性别:"+sex);
System.out.println("联系方式:"+contect);
}
}
package chap03;
import Impl.Person_Interface;
public class Add implements Person_Interface {
public void add(int x,int y){//x为天数,y为日资
int z=x*y;
System.out.println("薪资为:"+z);
}
}
package chap03;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("---------------job");
Student job=new Student("123456","computer",
"job","男","147258");
job.display();
System.out.println("---------------Tom");
Teacher Tom =new Teacher("159487","Tom","男","Java");
Tom.display();
}
Add abc=new Add();
abc.display();
}
最后为什么报错了呢?求解