Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Pair.java MrG 2011.1031
- public class Pair
- {
- private int x;
- private int y;
- /**
- Constructor: init 2 ints
- @param x is first int
- @param y is second int
- */
- public Pair(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- /**
- Accessor: find the sum
- @return the sum
- */
- public int getSum()
- {
- return x+y;
- }
- /**
- Accessor: find the difference
- @return the difference
- */
- public int getDiff()
- {
- return x-y;
- }
- /**
- Accessor: find the product
- @return the product
- */
- public int getProd()
- {
- return x*y;
- }
- /**
- Accessor: find the distance
- @return the distance
- */
- public int getDist()
- {
- return Math.abs(getDiff());
- }
- /**
- Accessor: find the average
- @return the average
- */
- public double getAVG()
- {
- return (double)getSum()/2;
- }
- /**
- Accessor: find the minimum
- @return the minimum
- */
- public int getMin()
- {
- return Math.min(x,y);
- }
- /**
- Accessor: find the maximum
- @return the maximum
- */
- public int getMax()
- {
- return Math.max(x,y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement