Results 1 to 4 of 4
  1. #1
    Czajkus is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

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

    thank you so much and please help!

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

  2. #2
    Amok is offline Member
    Join Date
    Sep 2012
    Location
    Australia
    Posts
    12
    Rep Power
    0

    Default 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;
    }
    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. #3
    Czajkus is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default 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

  4. #4
    Amok is offline Member
    Join Date
    Sep 2012
    Location
    Australia
    Posts
    12
    Rep Power
    0

    Default 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
    }
    Fix your code according to above code and run it. If you still got problem then let me know.

    Thanks

Similar Threads

  1. 2 pair Combination of four values.
    By nandhinianand in forum New To Java
    Replies: 18
    Last Post: 02-27-2012, 09:32 AM
  2. 2 pair Combination of four values.
    By nandhinianand in forum NetBeans
    Replies: 3
    Last Post: 09-15-2011, 08:45 AM
  3. Swapping pair of character in a string
    By HelpMePls in forum New To Java
    Replies: 2
    Last Post: 02-10-2011, 06:10 AM
  4. How to store property file into key value pair
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-05-2008, 11:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •