Advertisement
calcpage

C4X4_Pair.java

Nov 1st, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. //Pair.java MrG 2011.1031
  2. public class Pair
  3. {
  4.     private int x;
  5.     private int y;
  6.  
  7.     /**
  8.     Constructor: init 2 ints
  9.     @param x is first int
  10.     @param y is second int
  11.     */
  12.     public Pair(int x, int y)
  13.     {
  14.         this.x = x;
  15.         this.y = y;
  16.     }
  17.  
  18.     /**
  19.     Accessor: find the sum
  20.     @return the sum
  21.     */
  22.     public int getSum()
  23.     {
  24.         return x+y;
  25.     }
  26.  
  27.     /**
  28.     Accessor: find the difference
  29.     @return the difference
  30.     */
  31.     public int getDiff()
  32.     {
  33.         return x-y;
  34.     }
  35.  
  36.     /**
  37.     Accessor: find the product
  38.     @return the product
  39.     */
  40.     public int getProd()
  41.     {
  42.         return x*y;
  43.     }
  44.  
  45.     /**
  46.     Accessor: find the distance
  47.     @return the distance
  48.     */
  49.     public int getDist()
  50.     {
  51.         return Math.abs(getDiff());
  52.     }
  53.  
  54.     /**
  55.     Accessor: find the average
  56.     @return the average
  57.     */
  58.     public double getAVG()
  59.     {
  60.         return (double)getSum()/2;
  61.     }
  62.  
  63.     /**
  64.     Accessor: find the minimum
  65.     @return the minimum
  66.     */
  67.     public int getMin()
  68.     {
  69.         return Math.min(x,y);
  70.     }
  71.  
  72.     /**
  73.     Accessor: find the maximum
  74.     @return the maximum
  75.     */
  76.     public int getMax()
  77.     {
  78.         return Math.max(x,y);
  79.     }
  80.  
  81. }
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement