Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package inhert;
- public class PlayerV2 extends Player { // subclass -
- //consturtors should be public
- //field
- protected short weapons = 1; // step 1 add the field
- protected short stamina = 100;
- protected short strength = 50;
- protected int money = 1000;
- protected String faction = "team snake";
- public PlayerV2() { // the default constructor is being called
- }
- public PlayerV2(
- String name,
- String rank,
- String peacekeeper,
- int score,
- short health,
- short level,
- float experience,
- short weapons, // step 6 add the constructor argument list
- short stamina,
- short strength,
- int money,
- String faction
- )
- {
- //send data to superclass
- super(name,rank,peacekeeper,score,health,level,experience); // this pass all the data on the base class - transport to the base class
- // use subclass data
- // step 7 validate / use the subclass data
- setWeapons(weapons);
- setStamina(stamina);
- setStrength(strength);
- setMoney(money);
- setFaction(faction);
- }
- //super gets everything from the base class
- @Override //your telling the java compiler, your override , always use to override, helps you not make mistake
- public void Output() {
- super.Output(); // overriding the subclass method
- // step 5 add to output method
- System.out.println("Weapons:\t" + weapons);
- System.out.println("Stamina:\t" + stamina);
- System.out.println("Strength:\t" + strength);
- System.out.println("Money:\t\t" + money);
- System.out.println("Faction:\t" + faction);
- }
- //setter
- //step 2 add setter
- public boolean setWeapons(short weapons) {
- // step 3 add validation
- if(weapons >= 1 && weapons <= 10) {
- this.weapons = weapons;
- return true;
- }
- return false;
- }
- public boolean setStamina(short stamina) {
- if(stamina >= 0 && stamina <= 500) {
- this.stamina = stamina;
- return true;
- }
- return false;
- }
- public boolean setStrength(short strength) {
- if(strength >= 0 && strength <= 100) {
- this.strength = strength;
- return true;
- }
- return false;
- }
- public boolean setMoney(int money) {
- if(money >= -1000000 && money <= 1000000) {
- this.money = money;
- return true;
- }
- return false;
- }
- public boolean setFaction(String faction) {
- if(faction.equalsIgnoreCase("Team Snake")) {
- this.faction = "Team Snake";
- return true;
- } else if (faction.equalsIgnoreCase("Team Liquid")){
- this.faction = "Team Liquid";
- return true;
- }
- return false;
- }
- //getter
- // step 4 add a getter
- public short getWeapons() {return weapons;}
- public short getStamina() {return stamina;}
- public short getStrength() {return strength;}
- public int getMoney() {return money;}
- public String getFaction() {return faction;}
- public String getRankAndName() { return rank+" "+name;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement