ch.arrenbrecht.jcite.examples
Class Adder

java.lang.Object
  extended by ch.arrenbrecht.jcite.examples.Adder

public class Adder
extends java.lang.Object

Class that adds a specific value to other values. Typical usage:

Adder ten = new Adder( 10 );
int result = ten.addTo( 5 );
Note how we can omit the package specification of the target class if it resides in the same package as this class. If the class is in another package, we have to specify it:
System.out.println( "This code is in a different package." );

Author:
peo

Constructor Summary
Adder(int addThis)
          Creates a new adder.
 
Method Summary
static int add(int a, int b)
          Adds two numbers.
 int addTo(int x)
          Adds the number with which this Adder was constructed to the argument.
 int getAddend()
          Returns the addend which was passed to the constructor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Adder

public Adder(int addThis)
Creates a new adder.

Parameters:
addThis - the number added by addTo(int).
Method Detail

addTo

public int addTo(int x)
Adds the number with which this Adder was constructed to the argument. Typical usage:
Adder ten = new Adder( 10 );
int result = ten.addTo( 5 );

Parameters:
x - the number to add this Adder's number to.
Returns:
the sum.

add

public static int add(int a,
                      int b)
Adds two numbers. Example:
int sum = Adder.add( 1, 2 );
Note how, in the parameter documentation, we can cite from the current class's source directly, that is, omitting the target class part.

Parameters:
a - first addend, as in
return a + b;
b - second addend, as in
return a + b;

getAddend

public int getAddend()
Returns the addend which was passed to the constructor. As in:
Adder one = new Adder( 1 );
int addend = one.getAddend();
assertEquals( 1, addend );

Returns:
the addend.