用java编写小程序,急需要,考试用考,大家给力!!!还有一天就要考试了!!要求如下:
/*
*作者:lzxianren
*功能:编写一个Dog类,可以保存宠物的名字和品种,体重,健康状况等信息。
* 在Dog类中定义相应的方法,能够让宠物的主人得到宠物的名字,品种和体重以及健康状况信息。并定义相应的方法能够修改上述信息。
*/
public class Dog {
private String name;
private String kind;
private int weight;
private String health;
private Man host;
public Dog(){
}
public Dog(String name){
this.name=name;
}
public Dog(String name,String kind){
this.name=name;
this.kind=kind;
}
public Dog(String name,String kind, int weight){
this.name=name;
this.kind=kind;
this.weight=weight;
}
public Dog(String name,String kind, int weight,String health){
this.name=name;
this.kind=kind;
this.weight=weight;
this.health=health;
}
public void SetName(String name){
this.name=name;
}
public void SetKind(String kind){
this.kind=kind;
}
public void SetWeight(int weight){
this.weight=weight;
}
public void SetHealth(String health){
this.health=health;
}
public void SetHost(Man host){
this.host=host;
}
public String getName(){
return this.name;
}
public String getKind(){
return this.kind;
}
public int getWeight(){
return this.weight;
}
public String getHealth(){
return this.health;
}
public Man getHost(){
return this.host;
}
}
/*
* Man类
* 定义Man类,表示人,包含姓名,年龄,住址,电话等信息。在Man类中,做适当的定义,允许我们可以收养一只宠物。
*/
class Man{
private String name;
private int age;
private String address;
private int telephone;
private Dog dog=null;
public void bringUpADog(Dog dog){
this.dog=dog;
}
public String getName(){
return this.name;
}
public String getAddress(){
return this.address;
}
public int getAge(){
return this.age;
}
public int getTelephone(){
return this.telephone;
}
public Dog getDog(){
return this.dog;
}
}
/*
* 定义Police类,同时修改Dog类,使得当警察发现一只流浪的Dog时,可以根据Dog对象的相应方法,获得狗狗主人的姓名,地址信息。
*/
class Police extends Man{
public String getHostNameOfDog(Dog dog){
return dog.getHost().getName();
}
public String getHostAddressOfDog(Dog dog){
return dog.getHost().getAddress();
}
}