1. Member
Join Date
Apr 2009
Posts
4
Rep Power
0

## Math Program

Any idea how to do this? I'm going to need a java file plus a java tester file as well, right?

Write a program that prompts the user for two numbers, then prints
The sum
The difference
The product
The average
The distance (absolute value of the difference)
The maximum (the larger of the two)
The minimum (the smaller of the two)

To do so, implement a class
public class Pair
{
/**
Constructs a pair.
@param aFirst the first value of the pair
@param aSecond the second value of the pair
*/
public Pair(double aFirst, double aSecond) { . . . }

/**
Computes the sum of the values of this pair.
@return the sum of the first and second values
*/
public double getSum() { . . . }
. . .
}

Then implement a class PairTester that constructs a Pair object, invokes its methods, and prin

2. Hi,

yes it seems really easy: 2 classes: Pair and PairTester, anyway IMHO a main method in the class Pair would suffice. Well, move on with your homework ;)

edit:
oh yes: don't forget to format your double values appropriate, because nobody likes doubles like 0.100000000000000893473
Last edited by mcfrog; 04-02-2009 at 08:26 PM. Reason: i forgot something about the format

3. Member
Join Date
Apr 2009
Posts
4
Rep Power
0
Now if I only knew where to start lol. My teacher spends about 90% of the class talking about the old days. Sucks.

4. well that's easy, but I don't know what knowledge you already have, so here's the long version:

* you create two files named after the classes and
* create the constructor given by your teacher
Java Code:
`public Pair(double aFirst, double aSecond) { . . . }`
* to have values to work with you need also to member variables of the same type, double, ... um... make them private members to keep nosy classes away :D
* create the mentioned methods and let your mathematical genius roll and return the values in the fashion of
Java Code:
`/** your javadoc here */ public double getSum() { return this.firstValue + this.secondValue; }`
This really would suffice for sum. Anything clear?

so long

5. Member
Join Date
Apr 2009
Posts
4
Rep Power
0
Ah, I think I see now. I will let you all know. Thanks bud!

6. no prob, you're welcome. :) Anyway, consider to set the RESOLVED-marker for this thread soon.

But if you intend to get deeper into Java it maybe is a good idea to buy a good book and have Java programmers around you in order to shortcut the back-in-the-days-where-we-had-punchcards if your teacher doesn't teach you very well.
Last edited by mcfrog; 04-02-2009 at 08:57 PM.

7. Member
Join Date
Apr 2009
Posts
4
Rep Power
0
Funny you mention punch cards cuz he brings that up a lot.

8. every teacher comes up with that story. Personally I think all these punchcard-talk is urban myth. There never have been punchcards. it's a created diversion in order not to see the real problems: the lack of good teaching :)