电子宠物

import java.util.*;
class Dog
{ private String name="hua";
  private int health=100;
  private int love=50;
  private String breed="拉布拉多";
  public String  getName(){return name;}
  public int getHealth(){return health;}
  public int getLove(){return love;}
  public String getBreed(){return breed;}
  Dog(String name,int health,int love,String breed)
{   this.name=name;
        this.health=health;
this.love=love;
this.breed=breed;
     }
 public void speak()
{
  System.out.println("狗狗的名字叫:"+getName()+"健康值为:"
  +getHealth()+"与主人的亲密度为:"+getLove()+"我的品种为:"+getBreed());
     }
}
class Penguin
{ private String name="无名";
  private int health=100;
  private int love=50;
  private String sex="Q仔";
  public String  getName(){return name;}
  public int getHealth(){return health;}
  public int getLove(){return love;}
  public String getSex(){return sex;}
  Penguin(String name,int health,int love,String sex)
{   this.name=name;
        this.health=health;
this.love=love;
this.sex=sex;
     }
  public void speak()
{
  System.out.println("狗狗的名字叫:"+getName()+"健康值为:"
  +getHealth()+"与主人的亲密度为:"+getLove()+"我的性别为:"+getSex());
     }
}
class PlayGame
{ public void playGame()
{
int a=0;
int b=50;
    Scanner input=new Scanner(System.in);
System.out.println("请输入两个1-100之间的数:");
 
a=input.nextInt();
 
do{
if(a>b) 

{System.out.println("数字偏大");
            System.out.println("请按照提示继续输入两个1-100之间的数:");
             a=input.nextInt();}

if(a<b)  
{System.out.println("数字偏小");
             System.out.println("请按照提示继续输入两个1-100之间的数:");
 a=input.nextInt();}
 
if(a==b)
{System.out.println("恭喜答对了");
             System.out.println("请按照提示继续输入两个1-100之间的数:");
             a=input.nextInt();}
}while(a!=b);

}
}
public class  PetShop
{ public static void main(String[] args)
{ PlayGame w=new PlayGame();
     Scanner input=new Scanner(System.in);
     System.out.println("欢迎来到宠物商店!");
     System.out.println("请输入宠物的名字!");
     String name=input.next();
     System.out.println("请选择您要领养的宠物类型:1、狗狗 2、企鹅");
     switch(input.nextInt())
{case 1:
            System.out.println("请选择狗狗的品种:1、拉布拉多 2、雪纳瑞");
             String breed;
int health;
int love;
if(input.nextInt()==1)
breed="拉布拉多";
 else
breed="雪纳瑞";
//创建狗对象
Dog dog=new Dog(name,55,55,breed);
dog.speak();
w.playGame();


break;
case 2:
   System.out.println("请选择企鹅的性别 1、Q仔 2、Q妹");
       String sex=null;
            if(input.nextInt()==1)
sex="Q仔";
else
sex="Q妹";
//创建企鹅对象
Penguin pen=new Penguin(name,55,55,sex);
pen.speak();
w.playGame();
break;
     default:System.out.println("不可行");
}
}




}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值