求一道java题目解答!
医生有姓名(name),编号(idNumber),地址(address)等基本信息,都有display()显示信息的方法。医生又分专业医生和非专业医生,非专业医生所具有的...
医生有姓名(name),编号(idNumber),地址(address)等基本信息,都有display()显示信息的方法。医生又分专业医生和非专业医生,非专业医生所具有的信息与上述的一样。但专业医生出了具有上述的基本信息之外还有特有的信息:专业(speciality)。请根据他们之间的关系,创建一个医生类(Doctor),包含医生的基本信息。再利用继承创建一个非专业医生类(NonSpecialist )和一个专业医生类(Specialist),专业医生类包含一个显示其专业的方法。利用这些类的对象显示他们各自的信息。
小弟是才学java的菜鸟。。遇到问题了。。请老鸟们帮帮忙!。顺便找个师傅!谢谢! 展开
小弟是才学java的菜鸟。。遇到问题了。。请老鸟们帮帮忙!。顺便找个师傅!谢谢! 展开
2个回答
展开全部
package com.answer;
class Doctor {
private int idNumber;
private String name;
private String address;
public int DisplayIdNumber() {
return idNumber;
}
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
public String DisplayName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String DisplayAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
class NonSpecialist extends Doctor{
}
class Specialist extends Doctor{
private String spaciality;
public String getSpaciality() {
return spaciality;
}
public void setSpaciality(String spaciality) {
this.spaciality = spaciality;
}
}
public class Main{
public static void main(String[] args) {
Specialist spc = new Specialist();
spc.setName("张三");
spc.setIdNumber(101);
spc.setAddress("北京第四医院门诊精神科");
spc.setSpaciality("脑神经外科");
System.out.println("编号:"+spc.DisplayIdNumber()+"\t姓名:"+spc.DisplayName());
System.out.println("地址:"+spc.DisplayAddress()+"\t专业:"+spc.getSpaciality());
}
}
class Doctor {
private int idNumber;
private String name;
private String address;
public int DisplayIdNumber() {
return idNumber;
}
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
public String DisplayName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String DisplayAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
class NonSpecialist extends Doctor{
}
class Specialist extends Doctor{
private String spaciality;
public String getSpaciality() {
return spaciality;
}
public void setSpaciality(String spaciality) {
this.spaciality = spaciality;
}
}
public class Main{
public static void main(String[] args) {
Specialist spc = new Specialist();
spc.setName("张三");
spc.setIdNumber(101);
spc.setAddress("北京第四医院门诊精神科");
spc.setSpaciality("脑神经外科");
System.out.println("编号:"+spc.DisplayIdNumber()+"\t姓名:"+spc.DisplayName());
System.out.println("地址:"+spc.DisplayAddress()+"\t专业:"+spc.getSpaciality());
}
}
展开全部
以前有过这么一个题你看哈:
public class Doctor {
String name,address;
int id;
public void show(String name,String address,int id){
System.out.println("姓名是: "+name+" 地址是: "+address+" 编号: "+id);
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class NonSpecialist extends Doctor{
public static void main(String args[]){
NonSpecialist l=new NonSpecialist();
l.show("高小","四川", 1);
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class Specialist extends Doctor
{
String speciality;
Specialist(String speciality,String name,String address,int id)
{
super.show(name, address, id);
this.speciality=speciality;
System.out.println("专业: "+speciality);
}
public static void main(String args[]){
new Specialist("外科","蝴蝶结","四川",3);
}
}
public class Doctor {
String name,address;
int id;
public void show(String name,String address,int id){
System.out.println("姓名是: "+name+" 地址是: "+address+" 编号: "+id);
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class NonSpecialist extends Doctor{
public static void main(String args[]){
NonSpecialist l=new NonSpecialist();
l.show("高小","四川", 1);
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class Specialist extends Doctor
{
String speciality;
Specialist(String speciality,String name,String address,int id)
{
super.show(name, address, id);
this.speciality=speciality;
System.out.println("专业: "+speciality);
}
public static void main(String args[]){
new Specialist("外科","蝴蝶结","四川",3);
}
}
参考资料: 0.0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |