1. Member
Join Date
Oct 2012
Posts
2
Rep Power
0

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;
}
}```
the carrots appear underneath in "aFirst and aSecond" under the "a"

Alex =)
Last edited by Czajkus; 10-01-2012 at 07:11 AM.

2. Member
Join Date
Sep 2012
Location
Australia
Posts
12
Rep Power
0

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;
}
change first = double aFirst to first = aFirst;
second = double aSecond to second = aSecond;

I am also assuming that you already have defined first and second as instance variables in your program

3. Member
Join Date
Oct 2012
Posts
2
Rep Power
0

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

Alex

4. Member
Join Date
Sep 2012
Location
Australia
Posts
12
Rep Power
0

Java Code:
```public class Pair
{

private double first;
private double second;

public Pair(double aFirst, double aSecond)
{
first = aFirst;     // this is where your problem was
second = aSecond;
}

public double getSum()
{
return first + second;
}

// and all other methods
}```
Fix your code according to above code and run it. If you still got problem then let me know.

Thanks