Java program to deal with a "pair" of numbers?
I need help. For this exercise you will implement a class called Pair,
that represents a pair of two numbers.The Pair class should include the
following constructor and methods:
CONSTRUCTORS public Pair(double num1, double num2) -- Creates an object
that represents a pair of double values
METHODS public double getAverage() -- Returns the average value of the two
numbers
public double getDistance() -- Returns the absolute vale of the distance
between the two numbers
public double getMaximum() -- Returns the maximum value of the two numbers
public double getMinimum() -- Returns the minimum vale of the two numbers
Write a class called PairTest that tests your Pair implementation. The
PairTest should prompt the user for the two values, create a Pair object
with the values and then print the average, distance, maximum, and minimum
of the pair. The input / output should look like the following:
Enter the first number: 5.5 Enter the second number: 3.0
Average: 4.25 Distance: 2.5 Maximum: 5.5 Minimum: 3.0
NOTE: For this exercise, your solution should not use any conditional
statements. Instead you should use the methods provided by
thejava.util.Math.
No comments:
Post a Comment