IvaAnd

Player

Nov 8th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. package FootbalTeamGenerator;
  2.  
  3. public class Player {
  4. private String name;
  5. private int endurance;
  6. private int sprint;
  7. private int dribble;
  8. private int passing;
  9. private int shooting;
  10.  
  11. public Player(String name, int endurance, int sprint, int dribble, int passing, int shooting) {
  12. this.setName(name);
  13. this.setEndurance(endurance);
  14. this.setSprint(sprint);
  15. this.setDribble(dribble);
  16. this.setPassing(passing);
  17. this.setShooting(shooting);
  18. }
  19.  
  20.  
  21. private void setName(String name) {
  22. Validator.nameIsValid(name);
  23. this.name = name;
  24. }
  25.  
  26. public String getName() {
  27. return this.name;
  28. }
  29.  
  30. private void setEndurance(int stat) {
  31. if (stat < 0 || stat > 100) {
  32. throw new IllegalArgumentException("Endurance should be between 0 and 100.");
  33. }
  34. this.endurance = stat;
  35. }
  36.  
  37. private void setSprint(int stat) {
  38. if (stat < 0 || stat > 100) {
  39. throw new IllegalArgumentException("Sprint should be between 0 and 100.");
  40. }
  41. this.sprint = stat;
  42. }
  43.  
  44. private void setDribble(int stat) {
  45. if (stat < 0 || stat > 100) {
  46. throw new IllegalArgumentException("Dribble should be between 0 and 100.");
  47. }
  48. this.dribble = stat;
  49. }
  50.  
  51. private void setPassing(int stat) {
  52. if (stat < 0 || stat > 100) {
  53. throw new IllegalArgumentException("Passing should be between 0 and 100.");
  54. }
  55. this.passing = stat;
  56. }
  57.  
  58. private void setShooting(int stat) {
  59. if (stat < 0 || stat > 100) {
  60. throw new IllegalArgumentException("Shooting should be between 0 and 100.");
  61. }
  62. this.shooting = stat;
  63. }
  64.  
  65. public double overallSkillLevel() {
  66. return (this.endurance + this.sprint
  67. + this.dribble + this.passing
  68. + this.shooting) / 5.0;
  69. }
  70. }
Add Comment
Please, Sign In to add comment