給你寫了一份,你可以根據(jù)需要自己改改,如果有哪里不明吧追問就好了。望采納
十載的鄒城網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。全網(wǎng)整合營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整鄒城建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“鄒城網(wǎng)站設(shè)計”,“鄒城網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
public?class?Hero{
private?int?id;
private?String?name;
private?int?age;
private?String?uniqueSkill;
//set、get方法
public?void?setId(int?id){
this.id=id;
}
public?int?getId(){
return?id;
}
public?void?setName(String?name){
this.name=name;
}
public?String?getName(){
return?name;
}
public?void?setAge(int?age){
this.id=id;
}
public?int?getAge(){
return?id;
}
public?void?setUniqueSkill(String?uniqueSkill){
this.uniqueSkill=uniqueSkill;
}
public?String?getUniqueSkill(){
return?uniqueSkill;
}
//輸出英雄信息
public?void?print(){
System.out.println("英雄編號\t英雄姓名\t英雄年齡\t英雄絕招");
System.out.println(getId()+"\t"+getName()+"\t"+getAge()+"\t"+getUniqueSkill());
}
}
public?class?Test{
public?static?void?main(String[]?args){
Scanner?scanner?=?new?Scanner(System.in);
//new對象
Hero?hero?=?new?Hero();
//輸入信息
System.out.println("請輸入英雄編號:");
hero.setId(scanner.nextInt());
System.out.println("請輸入英雄姓名:");
hero.setName(scanner.next());
System.out.println("請輸入英雄年齡:");
hero.setAge(scanner.nextInt());
System.out.println("請輸入英雄絕招:");
hero.setUniqueSkill(scanner.next());
//輸出信息
hero.print();
}
}
原因如下:
1 代碼中如果沒有自定義的構(gòu)造器,如你定義:public sdyxz(int id,String juezhao,String gongjili,int iq){...},那么程序中會默認存在構(gòu)造器public sdyxz(){}
2 由于你自己定義了一個,所以程序不產(chǎn)生默認構(gòu)造器public sdyxz(){},造成sdyxz a1=new sdyxz()編譯報錯
3 如果想sdyxz a1=new sdyxz()能用,那么加入代碼public sdyxz(){}即可
不太明白你的意思
在java里面來說的話,這個英雄人物就是一對象
public class Object{
private String name;//這個英雄的名字
private String skill_one;//他其中的一個技能
private String skill_two;//第二個技能
…………
/**
這里寫get 和 set方法
**/
}
在具體創(chuàng)建這個英雄人物的時候,只需要new Object,然后給這個object set技能.
完成!?。。?!
=====================================
public class Person {
private String name;// 英雄的名字
private String skill_1;// 技能1
private String skill_2;// 技能2
private String skill_3;// 技能3
private String skill_4;// 技能4
private String skill_5;// 技能5
private String skill_6;// 技能6
private String skill_7;// 技能7
private String skill_8;// 技能8
private String skill_9;// 技能9
// 覺得不夠還可以加
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSkill_1() {
return skill_1;
}
public void setSkill_1(String skill_1) {
this.skill_1 = skill_1;
}
public String getSkill_2() {
return skill_2;
}
public void setSkill_2(String skill_2) {
this.skill_2 = skill_2;
}
public String getSkill_3() {
return skill_3;
}
public void setSkill_3(String skill_3) {
this.skill_3 = skill_3;
}
public String getSkill_4() {
return skill_4;
}
public void setSkill_4(String skill_4) {
this.skill_4 = skill_4;
}
public String getSkill_5() {
return skill_5;
}
public void setSkill_5(String skill_5) {
this.skill_5 = skill_5;
}
public String getSkill_6() {
return skill_6;
}
public void setSkill_6(String skill_6) {
this.skill_6 = skill_6;
}
public String getSkill_7() {
return skill_7;
}
public void setSkill_7(String skill_7) {
this.skill_7 = skill_7;
}
public String getSkill_8() {
return skill_8;
}
public void setSkill_8(String skill_8) {
this.skill_8 = skill_8;
}
public String getSkill_9() {
return skill_9;
}
public void setSkill_9(String skill_9) {
this.skill_9 = skill_9;
}
public Person(String name, String skill_1, String skill_2, String skill_3,
String skill_4, String skill_5, String skill_6, String skill_7,
String skill_8, String skill_9) {
super();
this.name = name;
this.skill_1 = skill_1;
this.skill_2 = skill_2;
this.skill_3 = skill_3;
this.skill_4 = skill_4;
this.skill_5 = skill_5;
this.skill_6 = skill_6;
this.skill_7 = skill_7;
this.skill_8 = skill_8;
this.skill_9 = skill_9;
}
}
這就是一個對象.......
在創(chuàng)建對象的時候,只需要Person p = new Person();
如果他有2個技能:
1個:72變
1個:上天下地
p.setSkill_1("72變");
p.setSkill_2("上天下地");
根據(jù)javax.imageio.IIOException: Can't read input file!異常,意思是無法讀取到文件,原因是background = ImageIO.read(new File(Game.class.getResource(
"/img/background.png").getFile()));代碼中的文件不在本地或者路徑不對,解決辦法是將圖片路徑填寫正確。
public?class?Hero?{
public?int?liliang;
public?int?tili;
public?int?mingjie;
public?void?skill(){
System.out.println("我用技能了?。?);
}
public?void?attack(){
System.out.println("我要打人了?。?);
}
public?void?move(){
System.out.println("我動了0.0?。?);
}
}
static?class?Hero{?//英雄類
private?String?name;//英雄的名字
private?Integer?experience;//經(jīng)驗值
private?Integer?level;?//英雄等級
private?Integer?attack;?//攻擊力
public?Hero(String?name){?//新建英雄的構(gòu)造方法
this.name?=?name;//輸入名字
this.experience?=?0;//初始經(jīng)驗值為0
this.level?=?1;//初始等級為1
this.attack?=?100;//初始攻擊力為100
}
public?void?AttackMonster(Monster?monster){?//攻擊怪物的方法
System.out.println("英雄"+this.name+"攻擊"+monster.getName()+"造成"+this.attack+"點傷害");
Integer?hp?=?monster.getHealthPoint();//怪物被攻擊前血量
if?(hp??this.attack)?{?//判斷?如果怪物的血量大于攻擊力
hp?=?hp?-?this.attack;//怪物的血量?就減少攻擊力的點數(shù)
}?else?{?//如果怪物的血量?等于或者小于攻擊力
hp?=?0;?//怪物血量為0?死亡
}
monster.setHealthPoint(hp);?//改變怪物被攻擊后的血量
System.out.println("怪物剩余血量"+hp);
if?(hp?==?0??this.level?18){?//如果怪物死亡?且英雄等級沒有達到最高的18級
System.out.println("英雄"+this.name+"的經(jīng)驗值增加"+monster.getExperience()+"點");
this.experience?=?this.experience?+?monster.getExperience();?//英雄的經(jīng)驗值?增加
if?(this.experience?=?level?*?100){?//設(shè)定?英雄升級所需經(jīng)驗值為?等級*100??如果英雄增加后的經(jīng)驗值達到升級條件
this.experience?=?this.experience?-?level*100;?//經(jīng)驗值減去當前升級需要的經(jīng)驗值?溢出的進入下一個等級經(jīng)驗
this.level?=?this.level?+?1;//英雄等級?+1
this.attack?=?this.attack?+?20;?//設(shè)定?每升一級英雄攻擊力?+20
System.out.println("英雄"+this.name+"升級了,等級+1,攻擊力+20,當前等級"+this.level+",當前攻擊力"+this.attack);
}
}
}
//獲取英雄名字的方法
public?String?getName()?{
return?name;
}
//改變英雄名字的方法
public?void?setName(String?name)?{
this.name?=?name;
}
//獲取英雄當前經(jīng)驗值的方法
public?Integer?getExperience()?{
return?experience;
}
//改變英雄當前經(jīng)驗值的方法
public?void?setExperience(Integer?experience)?{
this.experience?=?experience;
}
//獲取英雄當前等級的方法
public?Integer?getLevel()?{
return?level;
}
//改變英雄當前等級的方法
public?void?setLevel(Integer?level)?{
this.level?=?level;
}
//獲取英雄當前攻擊力的方法
public?Integer?getAttack()?{
return?attack;
}
//改變英雄當前攻擊力的方法
public?void?setAttack(Integer?attack)?{
this.attack?=?attack;
}
}
static?class?Monster{?//怪物類
private?String?name;?//怪物的名字
private?Integer?healthPoint;//生命值
private?Integer?level;//怪物等級
private?Integer?experience;?//怪物的經(jīng)驗值
public?Monster(String?name,Integer?level){?//創(chuàng)建怪物的構(gòu)造方法?參數(shù)?名字,等級
this.name?=?name;?//初始化怪物的名字
this.level?=?level;?//初始化怪物的等級
this.healthPoint?=?level?*?1000;?//初始化怪物的血量
this.experience?=?level?*?10;//初始化怪物的經(jīng)驗,英雄殺死后可獲得,設(shè)定怪物經(jīng)驗值為等級*10
}
public?Integer?getHealthPoint()?{
return?healthPoint;
}
public?void?setHealthPoint(Integer?healthPoint)?{
this.healthPoint?=?healthPoint;
}
public?Integer?getLevel()?{
return?level;
}
public?void?setLevel(Integer?level)?{
this.level?=?level;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?Integer?getExperience()?{
return?experience;
}
public?void?setExperience(Integer?experience)?{
this.experience?=?experience;
}
}
public?static?void?main(String[]?args)?throws?Exception?{
Hero?hero?=?new?Hero("德瑪西亞之力");?//新建一個英雄
Monster?monster?=?new?Monster("小兵",1);//新建一個小兵
do?{
hero.AttackMonster(monster);?//攻擊怪物
}while?(monster.getHealthPoint()?!=?0);??//如果怪物沒死?一直攻擊
}