Results 1 to 4 of 4
- 10-01-2012, 04:06 AM #1
Member
- 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:
the carrots appear underneath in "aFirst and aSecond" under the "a"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; 10-01-2012 at 07:11 AM.
- 10-01-2012, 04:39 AM #2
Member
- Join Date
- Sep 2012
- Location
- Australia
- Posts
- 12
- Rep Power
- 0
Re: I Need Help With Constructing A Pair! thank you! Please Help!
change first = double aFirst to first = aFirst;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
- 10-01-2012, 05:37 AM #3
Member
- 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
- 10-01-2012, 10:49 AM #4
Member
- Join Date
- Sep 2012
- Location
- Australia
- Posts
- 12
- Rep Power
- 0
Re: I Need Help With Constructing A Pair! thank you! Please Help!
Fix your code according to above code and run it. If you still got problem then let me know.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: 02-27-2012, 08:32 AM -
2 pair Combination of four values.
By nandhinianand in forum NetBeansReplies: 3Last Post: 09-15-2011, 07:45 AM -
Swapping pair of character in a string
By HelpMePls in forum New To JavaReplies: 2Last Post: 02-10-2011, 05:10 AM -
How to store property file into key value pair
By Java Tip in forum java.utilReplies: 0Last Post: 04-05-2008, 10:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks