Advertisement
NadezhdaGeorgieva

05 Football Team Generator

Mar 3rd, 2021
1,468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package FootballTeamGenerator;
  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.     private void setName(String name) {
  21.         if (name == null || name.trim().isEmpty()){
  22.             throw new IllegalArgumentException("A name should not be empty.");
  23.         }
  24.         this.name = name.trim();
  25.     }
  26.  
  27.     public String getName() {
  28.         return name;
  29.     }
  30.  
  31.     private void setEndurance(int endurance) {
  32.         validateStatus(endurance, "Endurance");
  33.         this.endurance = endurance;
  34.     }
  35.  
  36.     private void setSprint(int sprint) {
  37.         validateStatus(sprint, "Sprint");
  38.         this.sprint = sprint;
  39.     }
  40.  
  41.     private void setDribble(int dribble) {
  42.         validateStatus(dribble, "Dribble");
  43.         this.dribble = dribble;
  44.     }
  45.  
  46.     private void setPassing(int passing) {
  47.         validateStatus(passing, "Passing");
  48.         this.passing = passing;
  49.     }
  50.  
  51.     private void setShooting(int shooting) {
  52.         validateStatus(shooting, "Shooting");
  53.         this.shooting = shooting;
  54.     }
  55.  
  56.     private void validateStatus(int status, String statusName){
  57.         if (status < 0 || status > 100){
  58.             throw new IllegalArgumentException(statusName + " should be between 0 and 100.");
  59.         }
  60.     }
  61.  
  62.     public double overallSkillLevel(){
  63.         return (this.endurance
  64.                 + this.sprint
  65.                 + this.dribble
  66.                 + this.passing
  67.                 + this.shooting) / 5.00;
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement