admin管理员组文章数量:1122853
宠物
宠物类
package com.Pg;public class Pg {private String name;private String type;private String sex;private int health;private int love;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;}public String getSex(){return sex;}public void setSex(String sex) {this.sex = sex;}public int getHealth(){return health;}public void setHealth(int health) {if(health < 0||health >100) {this.health = 60;}else {this.health = health;}}public int getLove(){return love;}public void setLove(int love) {if(love < 0||love >100) {//love = 60;this.love = 60;return;}this.love = love;}}
测试类
package com.Pg;import java.util.Scanner;public class Main { static Scanner sc = new Scanner(System.in);public static void main(String[] args) {Pg k = new Pg();System.out.println("欢迎来到宠物店!");System.out.println("请输入狗狗的名字:");String newName = sc.next(); k.setName(newName);System.out.println("请输入宠物的类型:");System.out.println("1.狗狗 2.企鹅");String newType = sc.next();k.setType(newType);System.out.println("请输入企鹅的性别:");System.out.println("1.Q仔 2.Q妹");String newSex = sc.next();k.setSex(newSex);System.out.println("情输入企鹅的健康值:(1~100之间)");int newHealth = sc.nextInt();k.setHealth(newHealth);System.out.println("请输入亲密度:");int newLove = sc.nextInt();k.setLove(newLove);System.out.println("狗狗的自白");System.out.println("我的名字叫"+k.getName()+",健康值是"+k.getHealth()+",和主人的亲密度是"+k.getLove()+",我的性别是"+k.getSex()+",我是"+k.getType());} }
转载于:.html
本文标签: 宠物
版权声明:本文标题:宠物 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1702052867a528152.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论