package lianxi;
import java.io.*;
class Animal {
public Animal(String name, int age, String hairColor) {
super();
this.name = name;
this.age = age;
this.hairColor = hairColor;
}
String name;
int age;
String hairColor;
}
class Dog extends Animal {
public Dog(String name, int age, String hairColor) {
super(name, age, hairColor);
// TODO Auto-generated constructor stub
}
void print() {
System.out.println("名字:" + name + " 年龄: " + age + " 毛色:"
+ hairColor);
}
}
class Cat extends Animal {
public Cat(String name, int age, String hairColor) {
super(name, age, hairColor);
// TODO Auto-generated constructor stub
}
void print() {
System.out.println("名字:" + name + " 年龄: " + age + " 毛色:"
+ hairColor);
}
}
public class Test3 {
public static void main(String[] args) {
Dog d1 = new Dog("黑贝大黑", 5, "break");
Dog d2 = new Dog("京巴哈利", 3, "white");
Cat c1 = new Cat("波斯猫咪咪", 4, "yellow");
Cat c2 = new Cat("波斯猫加菲", 4, "yellow");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = null;
try {
s = br.readLine();
while (s != null) {
if (s.equals("大黑"))
d1.print();
else if (s.equals("哈利"))
d2.print();
else if (s.equals("咪咪"))
c1.print();
else if (s.equals("加菲"))
c2.print();
else if (s.equalsIgnoreCase("exit"))
break;
else
System.out.println("您找的动物不存在!");
s = br.readLine();
}
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}