This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Cannot find symbol variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot find symbol variable" Watch "Cannot find symbol variable" New topic
Author

Cannot find symbol variable

Yolanda Johnson
Greenhorn

Joined: Feb 21, 2005
Posts: 2
When I tried to compile my code, I get the error that my symbol variable cannot be found. Here is my code:

import java.util.Scanner;

public class DemoStudent
{

public static void main (String [] args)
{
//creating an instance of the DemoStudent class
std1 = new Student();
//std2 = new Student();
//std3 = new Student();

Scanner in = new Scanner(System.in);

//get first name & last name
System.out.println("Enter your first name.");
First = in.nextLine();
System.out.println("Enter your last name.");
Last = in.nextLine();

//get tuition amount
System.out.println("Enter full tuition amount.");
Tuition = in.nextLine();

std1.setFirst(first);
//std2.setFirst();
//std3.setFirst();
std1.setLast(last);
//std2.setLast();
//std3.setLast();
std1.setTuition(t);
//std2.setTuition();
//std3.setTuition();

printPayment(std1);
//printPayment(student2);
//printPayment(student3);

}

//This method expects to be passed a Student instance
//as an argument

//static void printPayment(Student std1);
{
//double paymt;
//Scanner scan = new Scanner(System.in);
//this method will accept a reference
//to a specific student
//System.out.println(std1.getFullName(std1));
//System.out.println("Current Tuition:" + std1.getTuition());


//accept payment
//System.out.println("Enter payment:");
//paymt = scan.nextDouble();
//std1.payTuition(paymt);
//System.out.println("Current Tuition:" + std1.getTuition());
}


{
//double paymt;
//Scanner scan = new Scanner(System.in);
//this method will accept a reference
//to a specific student
//System.out.println(std2.getFullName());
//System.out.println("Current Tuition:" + std2.getTuition());


//accept payment
//System.out.println("Enter payment:");
//paymt = scan.nextDouble();
//std1.payTuition(paymt);
//System.out.println("Current Tuition:" + std2.getTuition());
}

{
//double paymt;
//Scanner scan = new Scanner(System.in);
//this method will accept a reference
//to a specific student
//System.out.println(std3.getFullName());
//System.out.println("Current Tuition:" + std3.getTuition());


//accept payment
//System.out.println("Enter payment:");
//paymt = scan.nextDouble();
//std1.payTuition(paymt);
//System.out.println("Current Tuition:" + std3.getTuition());
}

}
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Yolanda!... Welcome to Javaranch,
This is webservices forum, I am moving your question to Java in General (beginner) forum for better responses.
Have a nice time here.
Balaji
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
There is more to the 1st compile error...



i.e., cannot find symbol
symbol: variable std1


std1 isn't declared.

Student std1 = new Student();


... then on to the next compile error.
Igor Stojanovic
Ranch Hand

Joined: Feb 18, 2005
Posts: 58
Hi Yolanda,

I was able to fix 8 errors, 4 are still remaining,plz copy&paste this code(fixed parts are in bold) and run javac compiler...




compiler will report 4 errors because you didn't write 4 methods and you are trying to use them; you have to write methods before you can pass something to them.The same goes to variables,if you want to use variable first you have to declare it and then you can initialize it for example:





I suggest you reading some introductory text about using variables in Java before you actually start programming and also take some short example first with 2-3 variables and only 1 method,after you fully understand that short example move on to more complicated examples,using many variables and many methods.




kind regards
Igor
[ February 21, 2005: Message edited by: Igor Stojanovic ]
 
Don't get me started about those stupid light bulbs.
 
subject: Cannot find symbol variable
 
Similar Threads
Calculating the distance between two points problem
Cannot find symbol variable
Need help on passing values from one method to another
help converting my code into classes and arrays
For loop not executing