用java写一个Chatacter类
时间: 2023-06-11 10:04:46 浏览: 49
好的,以下是用Java编写一个Character类的代码示例:
```java
public class Character {
private String name; //角色名
private int level; //等级
private int hp; //生命值
private int mp; //法力值
//构造方法
public Character(String name, int level, int hp, int mp) {
this.name = name;
this.level = level;
this.hp = hp;
this.mp = mp;
}
//getter和setter方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public int getMp() {
return mp;
}
public void setMp(int mp) {
this.mp = mp;
}
//打印角色信息
public void printInfo() {
System.out.println("角色名:" + name);
System.out.println("等级:" + level);
System.out.println("生命值:" + hp);
System.out.println("法力值:" + mp);
}
}
```
以上就是用Java编写一个Character类的代码示例。如果您有其他问题,请随时问我。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![xlsm](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)