Write a test program that creates a Person , Student , Employee , Faculty , and Staff , and invok

    Design a class named  Person and its two subclasses named  Student and Employee .Make  Faculty and  Staff subclasses of  Employee . A person has a name,address, phonenumber, and email address. A student has a class status (freshman,sophomore,junior, or senior). Define the status as a constant. An employee has an office,salary, and date hired. A faculty member has office hours and a rank. A staffmember has a title. Override the toString method in each class to display the class name and the person’s name.

    Write a test program that creates a Person , Student , Employee , Faculty , and  Staff , and invokes their  toString() methods.

public class Person {
	String name;  
	String address;  
	String telphone;  
	public Person(String n,String a,String t)
	{   
		name=n;   
		address=a;   
		telphone=t;  
	}  
	public String toString()
	{   
		return name+" Person";    
	}
	public void display(Person person)
	{
		System.out.println(person);
	}
}

public class Employee extends Person{
	String office;
	double salary;
	public Employee(String n,String a,String t,String o,double s)
	{
		super(n, a, t);
		office = o;
		salary = s;
	}
	public String toString()
	{
		return name+"employee";
	}
}

public class Student extends Person{
	final String class1="一年级";
	final String class2="二年级";
	final String class3="三年级";
    final String class4="四年级";
    public Student(String n,String a,String t)
    { 
    	super(n, a, t);
    } 
    public String toString()
    { 
    	return name+" Student";
    }
}

public class Faculty extends Employee{
	int Level;
	public Faculty (String n,String a,String t,String o,double w,int level) 
	{
		super(n, a, t, o, w);
		Level = Level;
	}
	public String toString()
	{
		return name+"Faculty";
	}
}


public class Staff extends Employee{
	String position;
	public Staff(String n,String a,String t,String o,double w,String p)
	{
		super(n,a,t,o,w);
		position=p;
	}
	public String toString()
	{
		return name+"staff";
	}	
}

public class Test {
	public static void main(String[] args) {	
	Person p = new Person("网", "数据库的","2345678" );
	p.display(p);
	Student s = new Student("王宏","河南省漯河市","15839652309");
	s.display(s);
	Employee e = new Employee ("李四","河南省漯河市","0395112222","人事局",222.00);
	e.display(e);
	Faculty f = new Faculty("明明", "河北", "11232312", "帮手", 234,1);
	f.display(f);
	Staff sta = new Staff("红红","河南省周口市","13849472334","人事科",345.00,"副局长");
	sta.display(sta);
	}
}




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值