5 Replies - 321 Views - Last Post: 07 February 2013 - 08:06 PM Rate Topic: -----

#1 ShadwClone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-January 13

Cannot find symbol

Posted 05 February 2013 - 10:49 PM

Hi, I'm starting to work with the equals and copy class, but my main problem is this annoying error message, but I have no idea what it means... please help.
Hw10.java:26: cannot find symbol
symbol  : constructor Point(Point)
location: class Point
      p2 = new Point(p1);


This is my code:
import java.io.*;
import java.util.Scanner;
//////////////////////////////////////////////////////////////////////
class Hw10
{
//--------------------------------------------------------------------
   public static void main ( String [] args ) throws Exception
   {
      Point p1 = new Point(2.1,3.4);
      Point p2 = new Point(5.2,7.3);

      System.out.println();
      System.out.println("p1 is " + p1);
      System.out.println("p2 is " + p2);

      System.out.println();
      System.out.println("p1 == p2      -> " + (p1==p2));
      System.out.println("p1.equals(p2) -> " + p1.equals(p2));

      p2 = new Point(2.1 + 1e-6, 3.4 - 1e-6);

      System.out.println();
      System.out.println("p1 == p2      -> " + (p1==p2));
      System.out.println("p1.equals(p2) -> " + p1.equals(p2));

      p2 = new Point(p1);

      System.out.println();
      System.out.println("p1 == p2      -> " + (p1==p2));
      System.out.println("p1.equals(p2) -> " + p1.equals(p2));

      p2 = p1.copy();

      System.out.println();
      System.out.println("p1 == p2      -> " + (p1==p2));
      System.out.println("p1.equals(p2) -> " + p1.equals(p2));
   }
//--------------------------------------------------------------------
} // end class Hw10
//////////////////////////////////////////////////////////////////////
class Point
{
   private double x,y;
//--------------------------------------------------------------------
   public Point ( double x, double y )
   {
      this.x = x;
      this.y = y;
   }
//--------------------------------------------------------------------
   public boolean equals ( Point that )
   {
      if ( (y - x) < 0.000001 || (x - y) < 0.000001 )
         return true;
      return false;
   }
//--------------------------------------------------------------------
   public Point copy()
   {
      return new Point(x, y);
   }
   
   public String toString()
   {
      return "Point(" + x + "00, " + y + "00)";
   }
} // end class Point
//////////////////////////////////////////////////////////////////////



Is This A Good Question/Topic? 0
  • +

Replies To: Cannot find symbol

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Cannot find symbol

Posted 05 February 2013 - 11:00 PM

Well, I feel that the error is caused because your compiler is not able to find the constructor for the line 26.

In other words, there is no constructor defined by you of the following type

public Point(Point)
{

}


regards,
Raghav

This post has been edited by raghav.naganathan: 05 February 2013 - 11:03 PM

Was This Post Helpful? 1
  • +
  • -

#3 ShadwClone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-January 13

Re: Cannot find symbol

Posted 05 February 2013 - 11:08 PM

View Postraghav.naganathan, on 05 February 2013 - 11:00 PM, said:

Well, I feel that the error is caused because your compiler is not able to find the constructor for the line 26.

In other words, there is no constructor defined by you of the following type

public Point(Point something)
{

}


regards,
Raghav


Oh... I see... I'm not really sure how that works though.. How could I go about telling the constructor to return p2 as p1?
Was This Post Helpful? 0
  • +
  • -

#4 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Cannot find symbol

Posted 05 February 2013 - 11:10 PM

Well, you can create another constructor that takes a Point as argument and add the code what you require to that constructor.

regards,
Raghav
Was This Post Helpful? 1
  • +
  • -

#5 ShadwClone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-January 13

Re: Cannot find symbol

Posted 05 February 2013 - 11:39 PM

Sorry, I still don't really get it.. I'm relatively new to Java.
Was This Post Helpful? 0
  • +
  • -

#6 k3y  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 205
  • Joined: 25-February 12

Re: Cannot find symbol

Posted 07 February 2013 - 08:06 PM

View PostShadwClone, on 06 February 2013 - 01:39 AM, said:

Sorry, I still don't really get it.. I'm relatively new to Java.

Read through this: http://docs.oracle.c...vaOO/index.html

It will probably clear up some stuff =D
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1