• 10-01-2012, 04:06 AM
Czajkus
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:

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 =)
• 10-01-2012, 04:39 AM
Amok
Quote:

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
• 10-01-2012, 05:37 AM
Czajkus
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
• 10-01-2012, 10:49 AM
Amok
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;
}