1.代码
package Demo2;
class Character{
private String name; //人物名字
private String nose; //人物鼻子
private String mouth; //人物嘴巴
private String eye; //人物眼睛
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNose() {
return nose;
}
public void setNose(String nose) {
this.nose = nose;
}
public String getMouth() {
return mouth;
}
public void setMouth(String mouth) {
this.mouth = mouth;
}
public String getEye() {
return eye;
}
public void setEye(String eye) {
this.eye = eye;
}
public Character() {
super();
}
public Character(String name, String nose, String mouth, String eye) {
super();
this.name = name;
this.nose = nose;
this.mouth = mouth;
this.eye = eye;
}
public void action(String name){
if(name.equalsIgnoreCase("孙悟空")){
System.out.println("孙悟空使用金箍棒大妖精");
}else if(name.equalsIgnoreCase("猪八戒")){
System.out.println("猪八戒使用锄头打妖精");
}else {
System.out.println("沙僧使用弯刀抢打妖精");
}
}
public void show(){
System.out.println(name+"外貌特征:"+nose+","+mouth+","+eye);
}
}
public class Person {
public static void main(String[] args) {
Character c1=new Character("孙悟空", "猴子鼻", "樱桃嘴", "火眼");
c1.show();
c1.action("孙悟空");
System.out.println();
Character c2=new Character("猪八戒", "帅哥鼻", "大头嘴", "媚人眼");
c2.show();
c2.action("猪八戒");
System.out.println();
Character c3=new Character("沙僧", "君子鼻", "憨厚嘴", "沙眼");
c3.show();
c3.action("沙僧");
}
}
2.截图