Ulam numbers (calculates your life expectancy if you want to) I'm new to Java and wanted to present to you my latest project: Ulam Numbers

/**


 * This class consists of some instance variables a constructor and some getter and setter methods
 * It is supposed to implement the Ulam numbers which are named after Stanislav Ulam
 * Furthermore we will make use of the numbers to calculate/foresee how old you or me will become
 * If this made you curious just enter your own birthday or that of a relative but be warned it might 
 * shock you to death.. Hehe.. 
 * 
 * @author  Jae
 * @version 1.0
 */
public class UlamNumber {

 private int number;

 /**
  * This is a constructor which is pretty self-explaining
  * 
 * @param number
 * describes the number the user can input like for example his/her birthday
 */
public UlamNumber(int number) {
     this.number = number;
 }

 /**
 * This is a method without parameters which implements the ulam algorithm
 * Furthermore it calculates your "age" by counting how many steps are needed till
 * you reach the number 1 and gives it out on the console
 */
public void ulamAlgorithm() {

     int counter = 0;

     while (number != 1) {
     if (number % 2 == 0) {
         number = number / 2;
         counter++;
         } else if (number % 2 != 0) {
             number = (number * 3) + 1;
             counter++;
         }  
     }

     if (counter == 1) {
         System.out.println("Unfortunately you will only become: " + counter + "  years old &gt;:-)");
     } else if (counter &lt; 100) {
         System.out.println("Unfortunately you will only become: " + counter + " years old =(");
     } else {
         System.out.println("Congratulation you will become " + counter + " years old =)");
     }
 }

/**
 * This is a getter method which is pretty self-explaining
 * 
 * @return number
 * is from the type integer which returns the current value of number
 */
public int getNumber() {
    return number;
}

/**
 * This is a setter method which is pretty self-explaining
 * 
 * @param number
 * is from the type integer which an user can input to change the current value of number
 */
public void setNumber(int number) {
    this.number = number;
}   
}


I'm sorry but I didn't write an explanation to the above stated things. You can also see this in my bad javadocs. If you have any hints/tips for improvements, please let me know.
This is a senseless use of objects.  What exactly is an UlamNumber object?  Consider how you might use this class:


 UlamNumber ulam = new UlamNumber(0);
 ulam.setNumber(20);
 ulam.ulamAlgorithm();    // ← prints something about your age
 ulam.getNumber();        // ← returns 1, not 20



That code tells you nothing about the task that it performs (if you ignore the comments).  In particular, ulamAlgorithm() does several things (count steps, compose a remark, and print it) — none of which is obvious from the name of the function.

What you want to write is

System.out.println(AgeCommenter.commentAbout(UlamSequence.countSteps(20)));


To make that happen:

public class UlamSequence {
    public static int countSteps(long number) {
        int steps;
        for (steps = 0; number &gt; 1; steps++) {
            number = (number % 2 == 0) ? number / 2
                                       : 3 * number + 1;
        }
        return steps;
    }
}


Note the use of the for-loop for counting.

And the AgeCommenter:

public class AgeCommenter {
    public static String commentAbout(int age) {
        String fmt =
            (age ==  1) ? "Unfortunately you will only become: %d year old &gt;:=)"
          : (age &lt; 100) ? "Unfortunately you will only become: %d years old =("
          :               "Congratulations, you will become %d years old =)";
        return String.format(fmt, age);
    }
}