宠物领养

文件1,建立Dog类:

package ch13;

import java.util.Scanner;

/**
* Created by liwenj on 2017/7/24.
*/
public class Dog {
String name;
/**
* 亲密度0-100之间
*/
int love = 0;
/**
* 健康度,初始100
*/
int health = 100;
/**
* 品种
*/
String strain;

void show() {
System.out.println("宠物的自白:");
System.out.println("我的名字叫" + name + ",和主人的亲密度是" + love + ",健康值是" + health + ",我是" + strain);
}

}

文件2,建立企鹅类:

package ch13;

/**
* Created by liwenj on 2017/7/24.
*/
public class Peng{
String name;
/**
* 亲密度0-100之间
*/
int love=0;
/**
* 健康度,初始100
*/
int health=100;
/**
* 品种
*/
String strain;

/**
* 性别
*/
String sex;
void show(){
System.out.println("宠物的自白:");
System.out.println("我的名字叫"+name+",和主人的亲密度是"+love+",健康值是"+health+",性别是"+sex);
}
}

文件3,实例化对象和方法
package ch13;

import java.util.Scanner;

/**
* Created by liwenj on 2017/7/24.
*/
public class PetChose {
String name;
int lei;
int strain;
int sex;
public static void main(String[] args) {
String n;
int s;
int l;
int se;
String sv="";
String sev="";
PetChose pet = new PetChose();
System.out.println("请输入你要领的宠物名字");
Scanner input = new Scanner(System.in);
pet.name = input.next();
n=pet.name;
System.out.println("请输入你要领的宠物的类型(1.狗狗/2.企鹅)");
pet.lei = input.nextInt();
l=pet.lei;
if (l==1) {
System.out.println("请输入你要领的宠物的品种(1.聪明的拉布拉多犬/2.酷酷的雪瑞娜)");
pet.strain = input.nextInt();
s = pet.strain;
switch (s) {
case 1:
sv = "聪明的拉布拉多犬";
break;
case 2:
sv = "酷酷的雪瑞娜";
break;
}
Dog dog=new Dog();
dog.name=n;
dog.strain=sv;
dog.show();
}
else if(l==2){
System.out.println("请输入宠物的性别(1.Q仔/2.Q妹)");
pet.sex=input.nextInt();
se=pet.sex;
switch (se){
case 1:
sev="Q仔";
break;
case 2:
sev="Q妹";
break;
}
Peng peng=new Peng();
peng.name=n;
peng.sex=sev;
peng.show();
}

}
}
posted @ 2017-07-25 10:26  斯丢皮德曼  阅读(252)  评论(0编辑  收藏  举报