Last active
August 29, 2015 13:57
-
-
Save firejox/9853358 to your computer and use it in GitHub Desktop.
A5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a5.s101201046; | |
public class A5 { | |
public static void main(String[] args) { | |
Hero[] heros; | |
int i; | |
heros = new Hero[3]; | |
heros[0] = new Wizard(); //set Wizard | |
((Wizard)heros[0]).HP_setter(30); | |
((Wizard)heros[0]).MP_setter(30); | |
((Wizard)heros[0]).PP_setter(30); | |
heros[1] = new Swordsman(); //set Swordsman | |
((Swordsman)heros[1]).HP_setter(30); | |
((Swordsman)heros[1]).MP_setter(30); | |
((Swordsman)heros[1]).PP_setter(30); | |
heros[2] = new Knight(); //set Knight | |
((Knight)heros[2]).HP_setter(30); | |
((Knight)heros[2]).MP_setter(30); | |
((Knight)heros[2]).PP_setter(30); | |
for (i = 0; i < 3; i++) //ouput the information | |
System.out.println(heros[i].Name_getter() + " HP: " + heros[i].HP_getter() | |
+ " MP: " + heros[i].MP_getter() | |
+ " PP: " + heros[i].PP_getter()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a5.s101201046; | |
public class Hero { | |
protected String Name; //Hero's name | |
protected float HP; //Hero's health point | |
protected float MP; //Hero's mana point | |
protected float PP; //Hero's power point | |
void Name_setter(String _Name) { //set name | |
Name = _Name; | |
} | |
void HP_setter(float hpp) { //set health point | |
HP = hpp; | |
} | |
void MP_setter(float mpp) { //set mana point | |
MP = mpp; | |
} | |
void PP_setter(float ppp) { //set power point | |
PP = ppp; | |
} | |
String Name_getter() { //get name | |
return Name; | |
} | |
float HP_getter() { //get health point | |
return HP; | |
} | |
float MP_getter() { //get mana point | |
return MP; | |
} | |
float PP_getter() { //get power point | |
return PP; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a5.s101201046; | |
public class Knight extends Hero { | |
Knight () { //construct Knight class | |
Name = "Knight"; | |
} | |
float HP_getter() { //set HP | |
return HP * 0.8f; | |
} | |
float MP_getter() { //set MP | |
return MP * 0.1f; | |
} | |
float PP_getter() { //set PP | |
return PP * 0.1f; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a5.s101201046; | |
public class Swordsman extends Hero { | |
Swordsman() { //construct Swordsman class | |
Name = "Swordsman"; | |
} | |
float HP_getter() { //set HP | |
return HP * 0.1f; | |
} | |
float MP_getter() { //set MP | |
return MP * 0.1f; | |
} | |
float PP_getter() { //set PP | |
return PP * 0.8f; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a5.s101201046; | |
public class Wizard extends Hero { | |
Wizard() { //construct Wizard class | |
Name = "Wizard"; | |
} | |
float HP_getter() { //set HP | |
return HP * 0.2f; | |
} | |
float MP_getter() { //set MP | |
return MP * 0.7f; | |
} | |
float PP_getter() { //set PP | |
return PP * 0.1f; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment