• 宠物


    宠物类

    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());
            
        }
    }

  • 相关阅读:
    spark连接MongoDB
    idea+scala+spark遇到的一些问题
    linux环境变量的配置
    sqoop的导入导出
    hive中一些常用的sql语句
    Unity 插件制作笔记(持续更新)
    linux-shutdown命令说明
    linux中的redis缓存服务器
    IceScrum敏捷开发工具的安装文档-官方最新版
    PHP设计模式系列
  • 原文地址:https://www.cnblogs.com/lev1/p/11173171.html
Copyright © 2020-2023  润新知