Cannot find symbol symbol:constructor

Cannot find symbol symbol:constructor

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2905 Views - Last Post: 31 January 2010 - 07:41 PM Rate Topic: -----

#1 Tobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 10

Cannot find symbol symbol:constructor

Posted 31 January 2010 - 04:04 PM

//PROGRAM: Exercise 6.15, Page 242
//Written by: Susan Anderosn
//Date: January 31, 2010
//Description: Enter in two sed1 and side 2 right triangle numbers
// to determine the hypotenuse calculation.

package weekthree;

//Need this class for entering in data.
import java.util.Scanner; //program class Scanner

public class Hypotenuse
{
private double hyp = 0;

// Hypotenuse Constructor
public Hypotenuse( double hyp1 )
{
hyp = hyp1; //hypotenuse const
}// end hypotenuse constructor

//Set hypotenuse values
public void setHyp1( double sd1, double sd2, double hyp1 )
{
hyp1 = Math.hypot( sd1, sd2 );
hyp = hyp1; //hypotenuse set
}//end set hypotenuse

//Retrieve hypotenuse
public double getHyp1()
{
return hyp;
}//end return hypotenuse

//____________________________//
//Main process
public static void main(String[] args)
{
// create a Hypotenuse object
Hypotenuse hyp = new Hypotenuse; //object

// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in ); //input

//Enter in the right triangle side 1
System.out.printf("Side 1: "); //prompt
double side1 = input.nextDouble(); //side 1

//Enter in the right triangle side 2
System.out.printf("Side 2: "); //prompt
double side2 = input.nextDouble(); //side 2

//Display the hypotensue
System.out.printf( "Hyptoensue %.2f ", hyp.getHyp1() ); //hypotenuse

}// end main

}// end class

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot find symbol symbol:constructor

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10467
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 04:08 PM

Please, :code:
Also, please remember to describe your errors specifically in the body of your post. Thanks for helping us help you! :)

Your problem lies at this line: Hypotenuse hyp = new Hypotenuse;. When you instantiate your Object, it should look like: Hypotenuse hyp = new Hypotenuse(someDoubleValueOrVariable); since you did not include a no-args constructor for your Hypotenuse class.
Was This Post Helpful? 0
  • +
  • -

#3 Tobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 10

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 04:17 PM

View Postmacosxnerd101, on 31 Jan, 2010 - 03:08 PM, said:

Please, :code:
Also, please remember to describe your errors specifically in the body of your post. Thanks for helping us help you! :)

Your problem lies at this line: Hypotenuse hyp = new Hypotenuse;. When you instantiate your Object, it should look like: Hypotenuse hyp = new Hypotenuse(someDoubleValueOrVariable); since you did not include a no-args constructor for your Hypotenuse class.


First I'm a student and don't understand how to connect the call between the public static main and the class. This is what I tried
Hypotenuse hyp = new Hypotenuse( double side1, double side2 ); It states it is not a statement. I tried Hypotenuse hyp = new Hypotenuse( side1, side2 ); Receive the message constructor not found.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10467
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 04:25 PM

When you go to define a method in a class, like in snippet 1, you include the type declaration in the param list b/c you are defining the type and order of the params this method is expecting. Then when you invoke the method elsewhere, you simply provide the valid arguments of matching type and order as expected. Notice how in snippet 2, I invoke the constructor with 2 double literals as was defined in snippet 1. Hopefully this has cleared up the reason why you got your first error; now for your second, you tried to call a constructor for Hypotenuse with two args, but it wasn't defined (just like the no-args constructor last time). And if it isn't defined in your class, it doesn't exist, so you can't invoke it.
//snippet 1
class Hypotenuse{
	public Hypotenuse(double side1, double side2){
		 ..code..
	}
}



//snippet 2
public static void main(String[] args){
	Hypotenuse hyp = new Hypotenuse(3.0, 4.0);
}


Was This Post Helpful? 0
  • +
  • -

#5 Tobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 10

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 05:59 PM

View Postmacosxnerd101, on 31 Jan, 2010 - 03:25 PM, said:

When you go to define a method in a class, like in snippet 1, you include the type declaration in the param list b/c you are defining the type and order of the params this method is expecting. Then when you invoke the method elsewhere, you simply provide the valid arguments of matching type and order as expected. Notice how in snippet 2, I invoke the constructor with 2 double literals as was defined in snippet 1. Hopefully this has cleared up the reason why you got your first error; now for your second, you tried to call a constructor for Hypotenuse with two args, but it wasn't defined (just like the no-args constructor last time). And if it isn't defined in your class, it doesn't exist, so you can't invoke it.
//snippet 1
class Hypotenuse{
	public Hypotenuse(double side1, double side2){
		 ..code..
	}
}



//snippet 2
public static void main(String[] args){
	Hypotenuse hyp = new Hypotenuse(3.0, 4.0);
}



/code
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in ); //input

double hypo = 0;

//Enter in the right triangle side 1
System.out.printf("Side 1: "); //prompt
double side1 = input.nextDouble(); //side 1

//Enter in the right triangle side 2
System.out.printf("Side 2: "); //prompt
double side2 = input.nextDouble(); //side 2

// create a Hypotenuse object
Hypotenuse hyp = new Hypotenuse( side1, side2, hypo ); //object

//Display the hypotensue
System.out.printf( "Hyptoensue %.2f ", hyp.getHyp1() ); //hypotenuse
/end of code

The answer is not calculated.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10467
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:03 PM

View PostTobie, on 31 Jan, 2010 - 07:17 PM, said:

View Postmacosxnerd101, on 31 Jan, 2010 - 03:08 PM, said:

Please, :code:
Also, please remember to describe your errors specifically in the body of your post. Thanks for helping us help you! :)

Your problem lies at this line: Hypotenuse hyp = new Hypotenuse;. When you instantiate your Object, it should look like: Hypotenuse hyp = new Hypotenuse(someDoubleValueOrVariable); since you did not include a no-args constructor for your Hypotenuse class.


You quoted my post when I asked you to use code tags, so you know what they are and how to use them. Please do so, as it makes your code a lot easier for us to read. Also, without seeing the definition of your Hypotenuse class (and all other relevant code) and a clearer description of your error, I cannot help you any further.
Was This Post Helpful? 0
  • +
  • -

#7 Tobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 10

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:15 PM

View Postmacosxnerd101, on 31 Jan, 2010 - 05:03 PM, said:

View PostTobie, on 31 Jan, 2010 - 07:17 PM, said:

View Postmacosxnerd101, on 31 Jan, 2010 - 03:08 PM, said:

Please, :code:
Also, please remember to describe your errors specifically in the body of your post. Thanks for helping us help you! :)

Your problem lies at this line: Hypotenuse hyp = new Hypotenuse;. When you instantiate your Object, it should look like: Hypotenuse hyp = new Hypotenuse(someDoubleValueOrVariable); since you did not include a no-args constructor for your Hypotenuse class.


You quoted my post when I asked you to use code tags, so you know what they are and how to use them. Please do so, as it makes your code a lot easier for us to read. Also, without seeing the definition of your Hypotenuse class (and all other relevant code) and a clearer description of your error, I cannot help you any further.

"//PROGRAM: Exercise 6.15, Page 242
//Written by: Susan Anderosn
//Date: January 31, 2010
//Description: Enter in two side1 and side 2 right triangle numbers
// to determine the hypotenuse calculation.

package weekthree;

//Need this class for entering in data.
import java.util.Scanner; //program class Scanner

public class Hypotenuse
{
private double hyp = 0;
private double sde1;
private double sde2;

// Hypotenuse Constructor
public Hypotenuse( double sd1, double sd2, double hyp1 )
{
sde1 = sd1;
sde2 = sd2;
hyp = hyp1; //hypotenuse const
}// end hypotenuse constructor

//Set hypotenuse values
public void setHyp1( double sd1, double sd2, double hyp1 )
{
hyp1 = Math.hypot( sd1, sd2 );
hyp = hyp1; //hypotenuse set
}//end set hypotenuse

//Retrieve hypotenuse
public double getHyp1()
{
return hyp;
}//end return hypotenuse

//____________________________//
//Main process
public static void main(String[] args)
{

// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in ); //input

double hypo = 0;

//Enter in the right triangle side 1
System.out.printf("Side 1: "); //prompt
double side1 = input.nextDouble(); //side 1

//Enter in the right triangle side 2
System.out.printf("Side 2: "); //prompt
double side2 = input.nextDouble(); //side 2

// create a Hypotenuse object
Hypotenuse hyp = new Hypotenuse( side1, side2, hypo ); //object

//Display the hypotensue
System.out.printf( "Hyptoensue %.2f ", hypo ); //hypotenuse

}// end main

}// end class
"
I'm apologies that there is a communication issue. This is the complete program.
The input values are not being passed to the Hypotenuse class. What do code do I need to correct?
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10467
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:16 PM

You quoted me twice when I asked you to include code tags, and yet you still won't. Please, :code:
:code:
:code:
Was This Post Helpful? 0
  • +
  • -

#9 Tobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 10

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:23 PM

View Postmacosxnerd101, on 31 Jan, 2010 - 05:16 PM, said:

You quoted me twice when I asked you to include code tags, and yet you still won't. Please, :code:
:code:
:code:

Please take my code and show me what you mean by code tags.
Thank you
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10467
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:24 PM

I'll let you practice with your code. However, here is an example:
System.out.println("Hello, world");



Notice the nice box with syntax highlighting that makes my code legible.
Was This Post Helpful? 0
  • +
  • -

#11 Tobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 10

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:27 PM

View Postmacosxnerd101, on 31 Jan, 2010 - 05:24 PM, said:

I'll let you practice with your code. However, here is an example:
System.out.println("Hello, world");



Notice the nice box with syntax highlighting that makes my code legible.

How do you do that type of print screen?
Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10467
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:30 PM

By using code tags like so: :code:
That's what I've been trying to tell you.
Was This Post Helpful? 0
  • +
  • -

#13 Tobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 10

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:37 PM

View PostTobie, on 31 Jan, 2010 - 05:27 PM, said:

View Postmacosxnerd101, on 31 Jan, 2010 - 05:24 PM, said:

I'll let you practice with your code. However, here is an example:
System.out.println("Hello, world");



Notice the nice box with syntax highlighting that makes my code legible.

How do you do that type of print screen?

I still don't understand the actual steps to complete the [code] command [code tag]. I looked through the drop down menus and didn't find anything that peratins to code tags.
Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10467
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 06:39 PM

View Postmacosxnerd101, on 31 Jan, 2010 - 09:24 PM, said:

I'll let you practice with your code. However, here is an example:
System.out.println("Hello, world");



Notice the nice box with syntax highlighting that makes my code legible.


Hit the Reply button with the double quotes for this post. Then look at the where the System.out.println("Hello, world"); line is. The tags before and after this line are code tags. That is how you use them. I don't really know how much clearer I can be. You can simply type them into your post as you will see when quoting my post here.
Was This Post Helpful? 0
  • +
  • -

#15 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Cannot find symbol symbol:constructor

Posted 31 January 2010 - 07:20 PM

View PostTobie, on 31 Jan, 2010 - 08:37 PM, said:

I still don't understand the actual steps to complete the [ code] command [ code tag]. I looked through the drop down menus and didn't find anything that peratins to code tags.


Follow what this says: :code:

Where your code begins, type "[ code]" after you've pasted your code in, type "[/ code]" (but WITHOUT the spaces in either)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2