Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Human{
- protected String name;
- protected int health;
- protected int armorLevel;
- protected int magicLevel;
- protected int experience;
- protected int level;
- Human(){
- name = "Andrew The Magic";
- health = 100;
- armorLevel = 1;
- magicLevel = 1;
- experience=0;
- level =1;
- }
- Human(String name){
- this(); //calling main constructor
- this.name = name;
- }
- void fight() {}
- void levelUp() {}
- void showAbility() { System.out.println("Name: "+name+" HP: "+health+" ARMOR: "+armorLevel+" MAGIC: "+magicLevel+" EXP: "+experience+" LVL: "+level); }
- void yell(){ System.out.println("IM A CHARACTER ;-("); }
- }
- //--------------------------------------------------------------
- class Warrior extends Human{
- Warrior(){
- super();
- }
- Warrior(String name){
- super(name);
- }
- void fight(){
- System.out.println("I attack with sword");
- experience +=10;
- if (experience >= 20 ){ levelUp(); }
- }
- void levelUp(){
- System.out.println("LEVEL UP!");
- health +=100;
- armorLevel +=25;
- level++;
- }
- void yell(){
- System.out.println("IM A GLORIOUS WARRIOR "+name);
- }
- }
- //--------------------------------------------------------------
- public class World{
- static void greeting(Human p){
- p.yell();
- }
- public static void main(String[] args){
- Warrior w = new Warrior("Noname the Warrior");
- w.showAbility();
- w.fight();
- w.showAbility();
- w.fight();
- w.showAbility();
- greeting(w);
- }
- }
- class Human {
- protected String name;
- protected int health;
- protected int armorLevel;
- protected int magicLevel;
- protected int experience;
- protected int level;
- Human() {
- name = "Andrew The Magic";
- health = 100;
- armorLevel = 1;
- magicLevel = 1;
- experience = 0;
- level = 1;
- }
- Human(String name) {
- this(); // calling main constructor
- this.name = name;
- }
- void fight() {
- }
- void levelUp() {
- }
- void showAbility() {
- System.out.println("Name: " + name + " HP: " + health + " ARMOR: "
- + armorLevel + " MAGIC: " + magicLevel + " EXP: " + experience
- + " LVL: " + level);
- }
- void yell() {
- System.out.println("IM A CHARACTER ;-(");
- }
- }
- // --------------------------------------------------------------
- class Warrior extends Human {
- Warrior() {
- super();
- }
- Warrior(String name) {
- super(name);
- }
- void fight() {
- System.out.println("I attack with sword");
- experience += 10;
- if (experience >= 20) {
- levelUp();
- }
- }
- void levelUp() {
- System.out.println("LEVEL UP!");
- health += 100;
- armorLevel += 25;
- level++;
- }
- void yell() {
- System.out.println("IM A GLORIOUS WARRIOR " + name);
- }
- }
- // --------------------------------------------------------------
- public class World {
- static void greeting(Human p) {
- p.yell();
- }
- public static void main(String[] args) {
- Warrior w = new Warrior("Noname the Warrior");
- w.showAbility();
- w.fight();
- w.showAbility();
- w.fight();
- w.showAbility();
- greeting(w);
- }
- }
- class Human {
- protected String name;
- protected int health;
- protected int armorLevel;
- protected int magicLevel;
- protected int experience;
- protected int level;
- Human() {
- name = "Andrew The Magic";
- health = 100;
- armorLevel = 1;
- magicLevel = 1;
- experience = 0;
- level = 1;
- }
- Human(String name) {
- this(); // calling main constructor
- this.name = name;
- }
- void showAbility() {
- System.out.println("Name: " + name + " HP: " + health + " ARMOR: "
- + armorLevel + " MAGIC: " + magicLevel + " EXP: " + experience
- + " LVL: " + level);
- }
- void yell() {
- System.out.println("IM A CHARACTER ;-(");
- }
- }
- protected int health;
- protected int armorLevel;
- protected int magicLevel;
- protected int experience;
- protected int level;
- class Human {
- protected String name;
- Human() {
- name = "Andrew The Magic";
- }
- Human(String name) {
- this(); // calling main constructor
- this.name = name;
- }
- void showAbility() {
- System.out.println("Name: " + name);
- }
- void yell() {
- System.out.println("IM A CHARACTER ;-(");
- }
- }
- // --------------------------------------------------------------
- class Warrior extends Human {
- protected int health;
- protected int armorLevel;
- protected int magicLevel;
- protected int experience;
- protected int level;
- Warrior() {
- super();
- health = 100;
- armorLevel = 1;
- magicLevel = 1;
- experience = 0;
- level = 1;
- }
- Warrior(String name) {
- super(name);
- health = 100;
- armorLevel = 1;
- magicLevel = 1;
- experience = 0;
- level = 1;
- }
- void fight() {
- System.out.println("I attack with sword");
- experience += 10;
- if (experience >= 20) {
- levelUp();
- }
- }
- void levelUp() {
- System.out.println("LEVEL UP!");
- health += 100;
- armorLevel += 25;
- level++;
- }
- void yell() {
- System.out.println("IM A GLORIOUS WARRIOR " + name);
- }
- }
- Warrior() {
- this("Andrew The Magic");
- }
- Warrior(String name) {
- super(name);
- health = 100;
- armorLevel = 1;
- magicLevel = 1;
- experience = 0;
- level = 1;
- }
- Human() {
- name = "Andrew The Magic";
- }
- Human(String name) {
- this.name = name;
- }
- static void greeting(Human p) { // Takes a Human as a parameter,
- // so a Warrior will be casted to a Human
- p.yell(); // call yell() in the class Human
- }
- class Human {
- protected String name;
- Human() {
- name = "Andrew The Magic";
- }
- Human(String name) {
- this.name = name;
- }
- void showAbility() {
- System.out.println("Name: " + name);
- }
- void yell() {
- System.out.println("I'M A CHARACTER ;-(");
- }
- }
- // --------------------------------------------------------------
- class Warrior extends Human {
- protected int health;
- protected int armorLevel;
- protected int magicLevel;
- protected int experience;
- protected int level;
- Warrior() {
- this("Andrew The Magic");
- }
- Warrior(String name) {
- super(name);
- health = 100;
- armorLevel = 1;
- magicLevel = 1;
- experience = 0;
- level = 1;
- }
- void fight() {
- System.out.println("I attack with sword");
- experience += 10;
- if (experience >= 20) {
- levelUp();
- }
- }
- void levelUp() {
- System.out.println("LEVEL UP!");
- health += 100;
- armorLevel += 25;
- level++;
- }
- void yell() {
- System.out.println("IM A GLORIOUS WARRIOR " + name);
- }
- }
- // --------------------------------------------------------------
- public class World {
- public static void main(String[] args) {
- Warrior w = new Warrior("Noname the Warrior");
- w.showAbility();
- w.fight();
- w.showAbility();
- w.fight();
- w.showAbility();
- w.yell();
- }
- }
- class Human {
- protected String name;
- protected int health = 100;
- protected int armorLevel = 1;
- protected int magicLevel = 1;
- protected int experience = 0;
- protected int level = 1;
- Human() {
- this("Andrew The Magic");
- }
- Human(String name) {
- this.name = name;
- }
- void fight() {} // Dubious, as mentioned above
- void levelUp() {} // Dubious, as mentioned above
- void showAbility() {
- System.out.printf("Name: %s HP: %d ARMOR: %d MAGIC: %d EXP: %d LVL: %dn",
- name, health, armorLevel, magicLevel, experience, level);
- }
- void yell() {
- System.out.println("IM A CHARACTER ;-(");
- }
- }
- public String toString(){
- return "Name: " + this.name; // Going by Manny Meng's feedback
- }
- void showAbility(){
- System.out.println(this);
- }
- //Warrior class.
- public String toString(){
- return super.toString() + "HP: " + this.health; //Add the rest.
- }
- // --------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement