Question: JUNIT TESTER FOR SOURCE CODE import java.util.Observable; public class Pokemon extends Observable{ private int myHealth; /** @invariant myHealth >=0 */ private int myAttackPower; /** @invariant
JUNIT TESTER FOR SOURCE CODE
import java.util.Observable;
public class Pokemon extends Observable{
private int myHealth; /** @invariant myHealth >=0 */ private int myAttackPower; /** @invariant myAttackPower >= 0 */ private String myName; /** @invariant myName != "" */ public Pokemon(String name, int initialHealth, int initialAttackPower) { myName = name; myAttackPower = initialAttackPower; myHealth = initialHealth; }
/** @return An int corresponding to the Pokemon's current health @custom.ensure getHealth() >= 0 */ public int getHealth() { return myHealth; }
/** @return An int corresponding to the Pokemon's current attack @custom.ensure getAttackPower() >= 0 */ public int getAttackPower() { return myAttackPower; }
/** @return A string corresponding to the Pokemon's name @custom.ensure getName() != "" */ public String getName() { return myName; }
/** @return Returns true of the Pokemon's health is zero, otherwise false */ public boolean isDead() { if (myHealth == 0) return true; return false; }
public void attack(Pokemon other) { other.takeDamage(this.myAttackPower, this); }
public void takeDamage(int amountOfDamage, Pokemon attacker) { int amtOfDamageActuallyDealt; if (amountOfDamage > myHealth) { amtOfDamageActuallyDealt = myHealth; myHealth = 0; } else { myHealth -= amountOfDamage; amtOfDamageActuallyDealt = amountOfDamage; } setChanged(); notifyObservers(new WhatHappened(this,attacker,"Body Slam",amtOfDamageActuallyDealt)); }
/** @return Returns a string corresponding the the state of the Pokemon */ public String toString() { String returnval = ""; returnval += "Pokemon " + myName + ": \thealth: " + myHealth + " \tattack: " + myAttackPower; return returnval; }
} // end class Pokemon
import java.util.Observer; import java.util.Observable; /** @author Christopher Summa @version 1.0
parse custom tags with the following command:
javadoc -tag custom.require:cm:"Precondition:" -tag custom.ensure:cm:"Postcondition:" -Xdoclint:none *.java
Specify an output directory for the generated files by adding the `-d ./doc` option of the above command.
Link to the java API by adding the `-link https://docs.oracle.com/javase/8/docs/api/` option as well. */ public class PokemonTrainer implements Observer {
private String myName; /** @invariant myName != "" */ /** @param name The name of the PokemonTrainer @since Monday, Sep 9, 2018
@custom.require name != "" */ public PokemonTrainer(String name) { myName = name; }
/** @return A string corresponding to the PokemonTrainer's name @custom.ensure getName() != "" */ public String getName() { return myName; }
@Override /** {@inheritdoc} */ public void update(Observable obs, Object o) { String whatHappened = ""; whatHappened += this + " is notified that " + o; System.out.println(whatHappened); }
/** @return Returns a string corresponding the the state of the PokemonTrainer */ public String toString() { String returnval = ""; returnval += "PokemonTrainer " + myName; return returnval; }
} // end class PokemonTrainer
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
