Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. package inhert;
  2.  
  3. public class PlayerV2 extends Player { // subclass -
  4. //consturtors should be public
  5.  
  6. //field
  7. protected short weapons = 1; // step 1 add the field
  8. protected short stamina = 100;
  9. protected short strength = 50;
  10. protected int money = 1000;
  11. protected String faction = "team snake";
  12.  
  13. public PlayerV2() { // the default constructor is being called
  14.  
  15. }
  16.  
  17. public PlayerV2(
  18. String name,
  19. String rank,
  20. String peacekeeper,
  21. int score,
  22. short health,
  23. short level,
  24. float experience,
  25. short weapons, // step 6 add the constructor argument list
  26. short stamina,
  27. short strength,
  28. int money,
  29. String faction
  30. )
  31. {
  32. //send data to superclass
  33. super(name,rank,peacekeeper,score,health,level,experience); // this pass all the data on the base class - transport to the base class
  34.  
  35. // use subclass data
  36. // step 7 validate / use the subclass data
  37. setWeapons(weapons);
  38. setStamina(stamina);
  39. setStrength(strength);
  40. setMoney(money);
  41. setFaction(faction);
  42.  
  43. }
  44.  
  45. //super gets everything from the base class
  46.  
  47. @Override //your telling the java compiler, your override , always use to override, helps you not make mistake
  48. public void Output() {
  49. super.Output(); // overriding the subclass method
  50. // step 5 add to output method
  51. System.out.println("Weapons:\t" + weapons);
  52. System.out.println("Stamina:\t" + stamina);
  53. System.out.println("Strength:\t" + strength);
  54. System.out.println("Money:\t\t" + money);
  55. System.out.println("Faction:\t" + faction);
  56.  
  57.  
  58. }
  59. //setter
  60. //step 2 add setter
  61.  
  62. public boolean setWeapons(short weapons) {
  63. // step 3 add validation
  64. if(weapons >= 1 && weapons <= 10) {
  65. this.weapons = weapons;
  66. return true;
  67. }
  68. return false;
  69. }
  70.  
  71. public boolean setStamina(short stamina) {
  72. if(stamina >= 0 && stamina <= 500) {
  73. this.stamina = stamina;
  74. return true;
  75. }
  76. return false;
  77. }
  78.  
  79. public boolean setStrength(short strength) {
  80. if(strength >= 0 && strength <= 100) {
  81. this.strength = strength;
  82. return true;
  83. }
  84. return false;
  85. }
  86.  
  87. public boolean setMoney(int money) {
  88. if(money >= -1000000 && money <= 1000000) {
  89. this.money = money;
  90. return true;
  91. }
  92. return false;
  93. }
  94.  
  95. public boolean setFaction(String faction) {
  96. if(faction.equalsIgnoreCase("Team Snake")) {
  97. this.faction = "Team Snake";
  98. return true;
  99. } else if (faction.equalsIgnoreCase("Team Liquid")){
  100. this.faction = "Team Liquid";
  101. return true;
  102. }
  103. return false;
  104. }
  105.  
  106. //getter
  107. // step 4 add a getter
  108. public short getWeapons() {return weapons;}
  109. public short getStamina() {return stamina;}
  110. public short getStrength() {return strength;}
  111. public int getMoney() {return money;}
  112. public String getFaction() {return faction;}
  113. public String getRankAndName() { return rank+" "+name;}
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement