title: How to make a method to update attributes of a class?
body: <p>I'm supposed to make a code in Java out of the following class diagram.<a href="https://i.stack.imgur.com/g07Y2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g07Y2.png" alt="UML Class Diagram"></a></p>
  
  <p>In the description of my assignment the following is stated; "One thing is completely missing from the class diagram, methods for updating the attributes. This is because the client of the system has decided that it is not allowed to update them. However, we know that this requirement will change, at least for age. The task therefore also includes designing and implementing a method for updating the age. When you do so, keep in mind that age can only increase, never decrease."</p>
  
  <p>My question is therefore How do I make a method to update attributes of a class - in this case increase age? :)</p>
  
  <p>2 other requirements down below (so you know why I included it in my code)... 
  "The tail length of a dog can be calculated with the neat formula:
  tail length = ålder⋅vikt10svanslängd = ålder⋅vikt10
  This formula applies to all dogs except taxis. One tax always has the tail length 3.7. Since kennel values ​​are international, both the Swedish word "tax" and the English "dachshund" must be handled correctly by the system."</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class Dog {
      private String name;
      private String breed;
      private int age;
      private int weight;
  
      public String getName() {
          return name;
      }
  
      public String getBreed() {
          return breed;
      }
  
      public int getAge() {
          return age;
      }
  
      public int getWeight() {
          return weight;
      }
  
      public double getTailLength() {
          double length;
          // Undantag för taxar/dachshunds (alltid svanslängd 3,7). 
          if (breed.equalsIgnoreCase ("Tax")  || breed.equalsIgnoreCase("Dachshund")) {
              length = 3.7;
          } else {
              //Formel för svanslängd
              length = (double)(age * weight) / 10;
          }
  
          return length;
      }
  
      public String toString() {
          return String;
      }
  }
  </code></pre>