doug5289
- 12
- 0
Homework Statement
Why am I getting an error message "Cannot find symbol"
The discussion revolves around troubleshooting a "Cannot find symbol" error in Java, particularly in the context of homework assignments. Participants explore various potential causes for the error, share code snippets, and seek solutions for related issues in their Java programs.
Participants generally agree on the need to declare variables properly and set colors in the graphics context, but there are multiple competing views regarding the specific causes of the "Cannot find symbol" error and how to resolve it. The discussion remains unresolved regarding the best approach to fix the compilation issues presented.
Some participants express uncertainty about the proper use of constructors and method calls, indicating that the code snippets provided may be incomplete or unclear. There are also unresolved questions about the correct implementation of color settings in the graphics context.
Students learning Java programming, particularly those encountering issues with graphics and object-oriented programming concepts, may find this discussion helpful.
Color myColor = new Color(255, 200, 150);
doug5289 said:I am trying to fill a rectangle and no matter what I put it doesn't fill it up. Any idea's?
g.fillRect(10, 10, 80, 30);
Mark44 said:LOL! Great minds think alike.![]()
You should put [ code] and [ /code] tags (without leading spaces) around your code. I have done this below.doug5289 said:I am getting this error while compiling this: Any help would sure be welcomed. I am in my first year and never dreamed it could be this hard.
E:\RistDouglas_DoubleMyNumberTester.java:21: cannot find symbol
symbol : constructor RistDouglas_DoubleMyNumber(int)
location: class RistDouglas_DoubleMyNumber
aDoubleMyNumberObject = new RistDouglas_DoubleMyNumber(num);
^
doug5289 said:Code:public class LastNameFirstName_DoubleMyNumberTester { //Class Non-Accessor/Non-Mutator Method public static void main (String[] args) { //Method's Local Variables int num, doubleNum; int DoubleMyNumber,aDoubleMyNumberObject; //Method's Statements //Display the purpose of the program. System.out.println("This program will take a programmer-defined " + "number and double it."); System.out.println(); //Prints a blank line. //Initialize the number. num = 7; //Construct the object. aDoubleMyNumberObject = new RistDouglas_DoubleMyNumber(); //Double the number. RistDouglas_DoubleMyNumber.doubleIt(); //Get the result. doubleNum = aDoubleMyNumberObject.getNumber(); //Display results. System.out.println("The result of doubling the number " + doubleNum + " is " + num + "."); System.out.println(); //Prints a blank line.
public class LastNameFirstName_DoubleMyNumberTester
{
//Class Non-Accessor/Non-Mutator Method
public static void main (String[] args)
{
//Method's Local Variables
int num, doubleNum;
int DoubleMyNumber,aDoubleMyNumberObject;
//Method's Statements
//Display the purpose of the program.
System.out.println("This program will take a programmer-defined " +
"number and double it.");
System.out.println(); //Prints a blank line.
//Initialize the number.
num = 7;
//Construct the object.
aDoubleMyNumberObject = new RistDouglas_DoubleMyNumber();
//Double the number.
RistDouglas_DoubleMyNumber.doubleIt();
//Get the result.
doubleNum = aDoubleMyNumberObject.getNumber();
//Display results.
System.out.println("The result of doubling the number " + doubleNum +
" is " + num + ".");
System.out.println(); //Prints a blank line.
// Mark44: no more code was shown.
}
}
public class RistDouglas_DoubleMyNumber
{
//Instance Variables
private int num, myNumber;
//Instance Constructor
public RistDouglas_DoubleMyNumber()
{
this.num = myNumber;
}
//Instance Mutator Method
public void setDouble(int doubleIt)
{
this.myNumber = myNumber * 2;
}
//Instance Accessor Method
public int getNumber()
{
return this.num;
}
}
aDoubleMyNumberObject = new RistDouglas_DoubleMyNumber();
RistDouglas_DoubleMyNumber numberObject = new RistDouglas_DoubleMyNumber(num);
public class RistDouglas_DoubleMyNumber
{
//Instance Variables
private int num, myNumber;
//Instance Constructor
public RistDouglas_DoubleMyNumber()
{
this.num = myNumber;
}
//Instance Mutator Method
public void setDouble(int doubleIt)
{
this.myNumber = myNumber * 2;
}
//Instance Accessor Method
public int getNumber()
{
return this.num;
}
}