java设计一个名为person的类和它的两个名为student和employee的子类
2018-04-06 20:04
483 查看
person,student,employee,faculty和staff类,设计一个名为person的类和它的两个名为student和employee的子类。employee类又有子类:教员类faculty和职员类staff。每个人都有姓名,地址电话号码和电子邮件地址。学生有班级状态。將这些常量定义为变量。—–java语言程序设计11.2
这里没有把常量定义为变量而是输入任意值
import java.util.*; public class eleven112 { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("student or employee?0 or 1:"); if(input.nextInt()==0) { System.out.print("enter the classstate:"); student a=new student(); String classstate=input.nextLine(); a.setclasstate(classstate); input.nextLine(); System.out.print("enter the name address tel email:"); String name=input.nextLine(); String address=input.nextLine(); String tel=input.nextLine(); String email=input.nextLine(); person b=new person(); b.setall(name, address, tel, email); System.out.println("classstate: "+a.get()+b.toString()); } else { System.out.print("enter salary: "); double salary=input.nextDouble(); input.nextLine(); System.out.print("enter office "); String office=input.nextLine(); staff c =new staff(); c.em(office, salary); System.out.print("enter the chenghao:"); c.chenghao=input.nextLine(); person d=new person(); System.out.print("enter the name address tel email:"); String name=input.nextLine(); String address=input.nextLine(); String tel=input.nextLine(); String email=input.nextLine(); d.setall(name, address, tel, email); System.out.println(d.toString()); System.out.println(c.toString()); } } } class student extends person{ private String classstate; public void setclasstate(String classtate) { this.classstate=classtate; } public String get() { return classstate; } } class employee extends person{ String office; double salary; public void em(String office,double salary) { this.office=office; this.salary=salary; } public String get() { return "office: "+office+"salary: "+salary; } } class staff extends employee{ String chenghao; public String toString() { return "office:"+super.office+"salary: "+super.salary+"称号:"+chenghao; } } class person{ String name,address,tel,email; public void setall(String name,String address,String tel,String email) { this.name=name; this.tel=tel; this.address=address; this.email=email; } public String toString() { return "name: "+name+"address: "+address+"tel: "+tel+"email: "+email; } }
相关文章推荐
- 实现一个名为Person的类和它的两个子类Student和Employee。
- 《JAVA继承与多态》【Person、Student、Employee类】(注:此题在书上原题基础上有修改)设计一个名为Person的类和它的两个名为Student和Employee子类。
- 设计一个“航空器”抽象类,由它派生出两个子类:“运输机”类和“客机”类
- 【Java】给定有向图,设计一个算法,找出两个结点之间是否存在一条路径
- Java设计person类,有姓名,年龄,性别。要求:该类至多只能创建一男,一女两个对象。
- 设计一个学生类Student和它的一个子类Undergraduate
- java--设计一个Person类
- java程序练习:尝试创建一个父类,在父类中创建两个方法,在子类中覆盖第二个方法,为子类创建一个对象,将他向上转型到基类并调用这个方法。
- 一个抽象类Shape 里边有两个抽象方法 计算面积 和 周长; Shape由三角形和圆形继承,利用多态的特性设计完成不同子类的功能
- java通过xstream将xml转换为java对象遇到的问题(一个对像中两个子类的类名相同)
- 5.18设计一个基类,再派生出两个子类
- JAVA课程设计-V-20161228-解决按一个菜单弹出两个窗口的BUG
- 设计一个窗口,窗口中包含有一个文本框,一个标签,两个按钮,当按下“文本一”按纽时,使得“Hello java!”显示在文本框中,按下“文本二”按纽时,使得“你好 Java!” 显示在文本框中(要求两个
- C#基础-039 设计一个学生类Student和它的一个子类Undergraduate,并进行测试
- 关于栈的弹出函数设计是否应该有两个返回值,一个表示数据,一个表示是否栈为空
- 关于栈的弹出函数设计是否应该有两个返回值,一个表示数据,一个表示是否栈为空
- Java:一个分数类的简单设计
- 实训JAVA语言设计——产生一个2-K之间的随机整数,判断一个数是否是素数
- 一个JAVA后台程序的设计方案
- 关于栈的弹出函数设计是否应该有两个返回值,一个表示数据,一个表示是否栈为空