DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Cannot find symbol (http://www.daniweb.com/forums/thread44466.html)

K.Duncan Apr 30th, 2006 12:34 pm
Cannot find symbol
 
I'm working on a fairly basic program and can not seem to get it to work. I've checked my spelling and all that; the only thing I can think of is my main isn't able to find my class file.

Here's the error message:

ComplexDemo.java:10: cannot find symbol
symbol : constructor Complex(double,double)
location: class Complex
Complex a=new Complex(9.9, 7.7);
^

And the constructor in the class file:

public void Complex(double x, double y)
{
real=x;
imaginary=y;
}

When I remove the values it works fine but that sort of defeats the purpose. Any suggestions?

-Kai

iamthwee Apr 30th, 2006 1:47 pm
Re: Cannot find symbol
 
Can't you have a setter method. For example...

Complex.java
/*
 * Complex.java
 *
 * Created on 30 April 2006, 17:37
 */


public class Complex {   
  private double imaginary;
  private  double real;
 
/**  @ Setter method
    *
    */   
 public void Set(double x, double y)
 {
    real = x;
    imaginary = y;
 }
 
 public void print()
 {
    System.out.println(real+" + "+imaginary+"i");
 }
   

}


Pedantic.java
/*
 *
 *
 * Created on 29 April 2006, 17:07
 */

class Pedantic {
   
public static void main (String [] args) {
   
Complex a = new Complex();
a.Set(9.3,2.4);
a.print();


}

}

K.Duncan Apr 30th, 2006 2:13 pm
Re: Cannot find symbol
 
That does work, but I'm more concerned as to why the method I used doesn't. Also, while I'm not positive, I think what I need to do requires initializing with the values. Thank you for the help.

-Kai

iamthwee Apr 30th, 2006 2:27 pm
Re: Cannot find symbol
 
You could probably get it to work using your way, but I don't like how it would read.

I dunno???

:sad:

K.Duncan Apr 30th, 2006 2:34 pm
Re: Cannot find symbol
 
Well, the set works at the very least, no complaints there. I do have one more little glitch in this thing however.

I've got two classes, Addition and Subtraction, designed to receive two Complex objects and return one. In my program I've got this written;

d=Addition(a,b);

That nets me a 'cannot find symbol' error. Any ideas? And thanks again for the help, I greatly appreciate it.

-Kai

K.Duncan Apr 30th, 2006 3:08 pm
Re: Cannot find symbol
 
Ah, nevermind. Changed it to d=d.Addition(a, b) and everything worked out. Guess that's what I get for missing about two weeks of classes.

-Kai

DeepZ May 3rd, 2006 6:21 pm
Re: Cannot find symbol
 
I think the problem is that :
public void Complex(double x, double y)

is not a constructor. A constructor does not have a return type, and yes, even void is a return type.

Change to :
public Complex(double x, double y)

and it should work, i think :cheesy:


All times are GMT -4. The time now is 3:03 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC