Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public class Dragon
  2. {
  3. private String attack;
  4. private int level;
  5.  
  6. // Write the constructor here!
  7. public Dragon (int theLevel, String theAttack)
  8. {
  9. attack = theAttack;
  10. level = theLevel;
  11. }
  12. // Put getters here
  13. public String getAttack()
  14. {
  15. return attack;
  16. }
  17. public int getLevel()
  18. {
  19. return level;
  20. }
  21. // Put other methods here
  22. public String fight()
  23. {
  24. String retStr = "";
  25. for(int i = 0; i < level; i++)
  26. {
  27. retStr += attack;
  28. }
  29. return retStr;
  30. }
  31. // String representation of the object
  32. public String toString()
  33. {
  34. return "Dragon is at level " + level + " and attacks with " + attack;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement