首页 > 分享 > 某人领养宠物狗案例

某人领养宠物狗案例

某人领养宠物狗案例

最新推荐文章于 2024-11-14 14:02:16 发布

今天吃鸡腿了吗 于 2022-07-11 19:51:18 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

public class Dog { private String name; private String type; //构造器 public Dog( String type) { this.type = type; } public Dog() { } //get和set方法 public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String type) { this.type = type; } }

--------------------------------------------------------- import java.util.Scanner; /**  * 人类  *  属性  *      姓名  *      拥有宠物狗  *  *  行为  *      领养狗  *      给狗起名字  *      介绍自己的宠物狗  */ public class Person { private String name; private Dog dog; public void adopDog(Dog dog){ System.out.println(this.name+"领养了"+dog.getType()+"品种的狗"); this.dog=dog; } public void giveName(){ if(this.dog==null){ System.out.println("领养一条狗"); return; } System.out.println("请输入狗的新名字"); String dogName =new Scanner(System.in).next(); this.dog.setName(dogName); } public void say(){ System.out.println("我叫"+name+",我有一条"+this.dog.getType()); System.out.println("品种的宠物狗,名字叫"+this.dog.getName()); } public Person(String name) { this.name = name; } public Person() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public Dog getDog() { return dog; } public void setDog(Dog dog) { this.dog = dog; } }

-----------------------------------------------------------------------------------------------

测试类 public class Test { public static void main(String[] args) { Dog d1= new Dog("中华田园犬"); Dog d2= new Dog("哈士奇"); Person p1= new Person("某人"); Person p2= new Person("x某人"); p1.adopDog(d2); p1.giveName(); p1.say(); } }

相关知识

某人领养宠物狗案例
英语造句子:sthhappendtosb.(某事发生在某人身上)showsthtosb=showsbsth(给某人看...)stealsthfromsb=stealsb'ssth(偷了某人的...)=(某人的...)hurrytodosth(匆忙干某事)see/sawsbdoingsth(看见某人正
免费领养宠物狗 遭骗运费
宠物领养平台? 怀化免费领养宠物狗?
net领养宠物项目案例.pptx
免费领养宠物狗?呵呵,相信你就输了
宠物领养的成功案例与启示
【宠物狗领养信息】
宠物狗领养
宠物领养的成功案例与感人故事

网址: 某人领养宠物狗案例 https://m.mcbbbk.com/newsview565885.html

所属分类:萌宠日常
上一篇: 哪些博客类型是最受欢迎的?
下一篇: 笔记:宠物管理