Results 1 to 4 of 4
 10012012, 05:06 AM #1Member
 Join Date
 Oct 2012
 Posts
 2
 Rep Power
 0
I Need Help With Constructing A Pair! thank you! Please Help!
hello thanks for looking, i was doing home work that tells me i have to construct a pair for 2 numbers to do the following things:
the sum
the difference
the product
the average
the distance (abs val)
maximum ( larger of two)
minimum(smaller of two)
so far here is my code:
Java Code: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){ first = double aFirst; //line 10 gets error ...\src\Pair.java:10: error: '.class' expected first = double aFirst; second = double aSecond; //line 11 gets error ...\src\Pair.java:11: error: '.class' expected second = double aSecond; } /** Computes the sum of the values of this pair. @return the sum of the first and second values */ public double getSum(){ double sum = (first + second); return sum; } /** Computes the difference of the values of this pair @return the difference of the first and second values */ public double getDifference(){ double difference = (first  second); return difference; } /** Computes the product of the values of this pair @return the product of the first and second values */ public double getProduct(){ double product = (first * second); return product; } /** Computes the average of the values of this pair @return the average of the first and second values */ public double getAverage(){ double average = (first + second / 2); return average; } /** Computes the distance of the values of this pair. @return the distance of the first and second values */ public double getDistance(){ double distance = (first / second); return distance; } /** Computes the maximum of the values of this pair. @return the maximum of the first and second values */ public double getMaximum(){ double maximum = (first * 2 * second * 2); return maximum; } /** Computes the minimum of the values of this pair. @return the minimum of the first and second values */ public double getMinimum(){ double minimum = (first * 2 + second *2); return minimum; } }
thank you so much and please help!
Alex =)Last edited by Czajkus; 10012012 at 08:11 AM.
 10012012, 05:39 AM #2Member
 Join Date
 Sep 2012
 Location
 Australia
 Posts
 12
 Rep Power
 0
Re: I Need Help With Constructing A Pair! thank you! Please Help!
public Pair(double aFirst, double aSecond){
first = double aFirst; //line 10 gets error ...\src\Pair.java:10: error: '.class' expected first = double aFirst;
second = double aSecond; //line 11 gets error ...\src\Pair.java:11: error: '.class' expected second = double aSecond;
}
second = double aSecond to second = aSecond;
I am also assuming that you already have defined first and second as instance variables in your program
 10012012, 06:37 AM #3Member
 Join Date
 Oct 2012
 Posts
 2
 Rep Power
 0
Re: I Need Help With Constructing A Pair! thank you! Please Help!
Thank you so much for replying +) ive tried every possible thing and i still get the same or worse error amount!
maybe my instance variable arent defined properly? any ideas?
sorry for being such a noob im in highschool so this stuff is pretty complicated
thanks in advance!
Alex
 10012012, 11:49 AM #4Member
 Join Date
 Sep 2012
 Location
 Australia
 Posts
 12
 Rep Power
 0
Re: I Need Help With Constructing A Pair! thank you! Please Help!
Java Code:public class Pair { //your instance variables private double first; private double second; //your constructor public Pair(double aFirst, double aSecond) { first = aFirst; // this is where your problem was second = aSecond; } //then your methods (your methods looks fine to me) public double getSum() { return first + second; } // and all other methods }
Thanks
Similar Threads

2 pair Combination of four values.
By nandhinianand in forum New To JavaReplies: 18Last Post: 02272012, 09:32 AM 
2 pair Combination of four values.
By nandhinianand in forum NetBeansReplies: 3Last Post: 09152011, 08:45 AM 
Swapping pair of character in a string
By HelpMePls in forum New To JavaReplies: 2Last Post: 02102011, 06:10 AM 
How to store property file into key value pair
By Java Tip in forum java.utilReplies: 0Last Post: 04052008, 11:16 AM
Bookmarks