码迷,mamicode.com
首页 > 编程语言 > 详细

Java作业

时间:2016-09-21 21:13:41      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

1、实现一个名为Person的类和它的子类EmployeeEmployee有两个子类Faculty和Staff。具体要求如下:

(1Person类中的属性有:姓名nameString类型),地址addressString类型),电话号码telphoneString类型)和电子邮件地址emailString类型);

(2Employee类中的属性有:办公室officeString类型),工资wagedouble类型),受雇日期hiredateString类型);

(3Faculty类中的属性有:学位degreeString类型),级别levelString类型);

(4Staff类中的属性有:职务称号dutyString类型)。

 

package text11;

public class Person {

        private String name;
        private String address;
        private String telphone;
        private String email;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getAddress() {
            return address;
        }
        public void setAddress(String address) {
            this.address = address;
        }
        public String getTelphone() {
            return telphone;
        }
        public void setTelphone(String telphone) {
            this.telphone = telphone;
        }
        public String getEmail() {
            return email;
        }
        public void setEmail(String email) {
            this.email = email;
        }
}





package text11;

public class Employee extends Person {
    private String office;
    private double wage;
    private String hiredate;
    public String getOffice() {
        return office;
    }
    public void setOffice(String office) {
        this.office = office;
    }
    public double getWage() {
        return wage;
    }
    public void setWage(double wage) {
        this.wage = wage;
    }
    public String getHiredate() {
        return hiredate;
    }
    public void setHiredate(String hiredate) {
        this.hiredate = hiredate;
    }
    
}




package text11;

public class Faculty extends Employee{
    private String degree;
    private String level;
    public String getDegree() {
        return degree;
    }
    public void setDegree(String degree) {
        this.degree = degree;
    }
    public String getLevel() {
        return level;
    }
    public void setLevel(String level) {
        this.level = level;
    }
    
}




package text11;

public class Staff extends Employee {
    private String duty;

    public String getDuty() {
        return duty;
    }

    public void setDuty(String duty) {
        this.duty = duty;
    }
    
}




package text11;

public class Test {
        public static void main(String[] args) {
            Faculty a=new Faculty();
            a.setName("张三");
            a.setAddress("张店区共青团路1号");
            a.setEmail("12345877@qq.com");
            a.setOffice("富丽商城A座407");
            a.setWage(4700);
            a.setHiredate("2013年4月1日");
            a.setTelphone("123456788");
            a.setDegree("本科");
            a.setLevel("一级");
            System.out.println("员工姓名:"+a.getName()+"\r\n"+"地址:"+a.getAddress()+"\r\n"+"e-mail:"+
            a.getEmail()+"\r\n"+"地址:"+a.getOffice()+"\r\n"+"工资:"+a.getWage()+"\r\n"+"入职时间:"+a.getHiredate()+
            "\r\n"+"电话:"+a.getTelphone()+"\r\n"+"学位:"+a.getDegree()+"\r\n"+"级别:"+a.getLevel());
            Staff b=new Staff();
            b.setName("李四");
            b.setAddress("张店区共人民路1号");
            b.setEmail("12345557@qq.com");
            b.setOffice("银座商城4楼4407");
            b.setWage(5500);
            b.setHiredate("2013年5月1日");
            b.setTelphone("123555588");
            b.setDuty("优秀员工");
            System.out.println("员工姓名:"+b.getName()+"\r\n"+"地址:"+b.getAddress()+"\r\n"+"e-mail:"+
            b.getEmail()+"\r\n"+"地址:"+b.getOffice()+"\r\n"+"工资:"+b.getWage()+"\r\n"+"入职时间:"+b.getHiredate()+
            "\r\n"+"电话:"+b.getTelphone()+"\r\n"+"职务等级:"+b.getDuty());
        }
    }

 

技术分享

 

Java作业

标签:

原文地址:http://www.cnblogs.com/wangguoning/p/5893945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!