Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Symbol not found error

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Symbol not found error

    Hello, When I execute my code, it comes up with this error.

    symbol  : variable type
    location: class Employee2
    		return type;
    		       ^
    \\puma\home\\Employee2.java:53: cannot find symbol
    symbol  : variable type
    location: class Employee2
    		type = "salaried";
    		^
    \\puma\home\\Employee2.java:55: cannot find symbol
    symbol  : variable type
    location: class Employee2
    		type = "hourly";
    		^
    \\puma\home\\Employee2.java:59: cannot find symbol
    symbol  : variable type
    location: class Employee2
    	if(type == "salary") {
    	   ^
    \\puma\home\\Employee2.java:68: cannot find symbol
    symbol  : variable type
    location: class Employee2
    	} else if (type == "hourly") {
    	           ^
    \\puma\home\\Employee2.java:75: cannot find symbol
    symbol  : variable type
    location: class Employee2
    	Employee2 Employee1 = new Employee2(name, type, rate, hours, salary, bonusPay);
    	                                          ^
    6 errors
     
    Process completed.
    Here is my code:
    import java.util.*;
     
     
     
    public class Employee2 {
    	//Varibales
    		private static double salary, rate, hours, weeklyPay = 0;
    	private static String name;
    	private static String typeH;
    	static boolean bonusPay = false;
     
    	//Constructor creates Employee object
    	public Employee2(String name, String status, double hours, double rate, double salary, boolean bonusPay) {
    		if (status == "salaried") {
    			this.salary = salary;
    			if(bonusPay == true) {
    				salary = salary * 1.1;
    			}
    		} else {
    			this.rate = rate;
    			this.hours = hours;
    			if(hours > 40) { //calculates and adds overtime pay
    				weeklyPay = (hours - 40) * (2*(salary)) + 40 * salary;
    			} else {
    				weeklyPay = rate * hours;
    			}
     
    		}
    	}
    	//Methods to obtain information about a specific employee
    	private double getWeeklyPay() {
    		return weeklyPay;
    	}private String getName() {
    		return name;
    	}private double getSalary() {
    		return salary;
    	}private String getType() {
    		return type;
    	}private double getHours() {
    		return hours;
    	}private double getRate() {
    		return rate;
    	}
     
    	private void printData(Employee2 x) {
     
    	}
    public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
    	System.out.println("Hello! Welcome to Employee Database");
    	System.out.println("If Employee is salaried enter S. Otherwise enter H for hourly");
    	if(input.nextLine().toLowerCase().contains("s")) {
    		type = "salaried";
    	} else if(input.nextLine().toLowerCase().contains("h")) {
    		type = "hourly";
    	}
    	System.out.println("Enter Employee's full name");
    	name = input.nextLine();
    	if(type == "salary") {
    		System.out.println("Enter weekly salary");
    		salary = input.nextDouble();
    		System.out.println("Enter Y if employee receives a bonus of 10%, otherwise enter N");
    		if(input.nextLine().toLowerCase().contains("y")) {
    			bonusPay = true;
    		} else {
    			bonusPay = false;
    		}
    	} else if (type == "hourly") {
    		System.out.println("Enter hourly pay");
    		rate = input.nextDouble();
    		System.out.println("Enter # of hours");
    		hours = input.nextDouble();
     
    	}
    	Employee2 Employee1 = new Employee2(name, type, rate, hours, salary, bonusPay);
     
    	 System.out.println();
       	 System.out.println("\t  Name          Status              Hours             Rate             Weekly Pay Amount");
       	 System.out.println("\t======================================================================");
       	 System.out.println(Employee1.getName() +              Employee1.getType() +          Employee1.getHours()             + Employee1.getRate()         + Employee1.getWeeklyPay());
       	 System.out.println();
        }
     
    }
    All help is appreciated thank you in advance;


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Symbol not found error

    There is no variable named type, perhaps you meant to use typeH instead.
    Also, it is almost never a good idea to compare String with ==. String are objects, so you should use the .equals() method instead.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Symbol not found error

    now I'm gettinga null pointer at line 53 (typeH = "salaried"
    import java.util.*;
     
     
     
    public class Employee2 {
    	//Varibales
    		private static double salary, rate, hours, weeklyPay = 0;
    	private static String name;
    	private static String typeH;
    	static boolean bonusPay = false;
     
    	//Constructor creates Employee object
    	public Employee2(String name, String status, double hours, double rate, double salary, boolean bonusPay) {
    		if (status.equals("salaried")) {
    			this.salary = salary;
    			if(bonusPay == true) {
    				salary = salary * 1.1;
    			}
    		} else {
    			this.rate = rate;
    			this.hours = hours;
    			if(hours > 40) { //calculates and adds overtime pay
    				weeklyPay = (hours - 40) * (2*(salary)) + 40 * salary;
    			} else {
    				weeklyPay = rate * hours;
    			}
     
    		}
    	}
    	//Methods to obtain information about a specific employee
    	private double getWeeklyPay() {
    		return weeklyPay;
    	}private String getName() {
    		return name;
    	}private double getSalary() {
    		return salary;
    	}private String getType() {
    		return type;
    	}private double getHours() {
    		return hours;
    	}private double getRate() {
    		return rate;
    	}
     
    	private void printData(Employee2 x) {
     
    	}
    public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
    	System.out.println("Hello! Welcome to Employee Database");
    	System.out.println("If Employee is salaried enter S. Otherwise enter H for hourly");
    	if(input.nextLine().toLowerCase().contains("s")) {
    		typeH = "salaried";
    	} else if(input.nextLine().toLowerCase().contains("h")) {
    		typeH = "hourly";
    	}
    	System.out.println("Enter Employee's full name");
    	name = input.nextLine();
    	if(typeH.equals("salaried")) {
    		System.out.println("Enter weekly salary");
    		salary = input.nextDouble();
    		System.out.println("Enter Y if employee receives a bonus of 10%, otherwise enter N");
    		if(input.nextLine().toLowerCase().contains("y")) {
    			bonusPay = true;
    		} else {
    			bonusPay = false;
    		}
    	} else if (	typeH.equals("hourly")) {
    		System.out.println("Enter hourly pay");
    		rate = input.nextDouble();
    		System.out.println("Enter # of hours");
    		hours = input.nextDouble();
     
    	}
    	Employee2 Employee1 = new Employee2(name, type, rate, hours, salary, bonusPay);
     
    	 System.out.println();
       	 System.out.println("\t  Name          Status              Hours             Rate             Weekly Pay Amount");
       	 System.out.println("\t======================================================================");
       	 System.out.println(Employee1.getName() +              Employee1.getType() +          Employee1.getHours()             + Employee1.getRate()         + Employee1.getWeeklyPay());
       	 System.out.println();
        }
     
    }

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Symbol not found error

    Most likely because typeH has not been initalized. Look at this code:
    if(input.nextLine().toLowerCase().contains("s")) {
    		typeH = "salaried";
    	} else if(input.nextLine().toLowerCase().contains("h")) {
    		typeH = "hourly";
    	}
    The Scanner.nextLine() method moves the pointer. So every time you call the nextLine() method, you are getting a different line. Is that what you intend on doing? What you should do is create a local String variable called line, or something, set line = input.nextLine(), and then use that in your if/else statements instead.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Junior Member
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Symbol not found error

    Thank you for your response, it is appreciated.
    I have a further problem.
    import java.util.*;
     
     
     
    public class Employee2 {
    	//Varibales
    		private static double salary, rate, hours, weeklyPay = 0;
    	private static String name;
    	private static String typeH;
    	static boolean bonusPay = false;
     
    	//Constructor creates Employee object
    	public Employee2(String name, String status, double hours, double rate, double salary, boolean bonusPay) {
    		if (status.equals("salaried")) {
    			this.salary = salary;
    			if(bonusPay == true) {
    				salary = salary * 1.1;
    			}
    		} else {
    			this.rate = rate;
    			this.hours = hours;
    			if(hours > 40) { //calculates and adds overtime pay
    				weeklyPay = (hours - 40) * (2*(salary)) + 40 * salary;
    			} else {
    				weeklyPay = rate * hours;
    			}
     
    		}
    	}
    	//Methods to obtain information about a specific employee
    	private double getWeeklyPay() {
    		return weeklyPay;
    	}private String getName() {
    		return name;
    	}private double getSalary() {
    		return salary;
    	}private String getType() {
    		return type;
    	}private double getHours() {
    		return hours;
    	}private double getRate() {
    		return rate;
    	}
     
    	private void printData(Employee2 x) {
     
    	}
    public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
    	private string line;
    	System.out.println("Hello! Welcome to Employee Database");
    	System.out.println("If Employee is salaried enter S. Otherwise enter H for hourly");
    	line = input.nextLine();
    	if(line.toLowerCase().contains("h")) {
    		line = "salaried";
    	} else if()) {
    		line = "hourly";
    	}
    	System.out.println("Enter Employee's full name");
    	name = input.nextLine();
    	if(line.equals("salaried")) {
    		System.out.println("Enter weekly salary");
    		salary = input.nextDouble();
    		System.out.println("Enter Y if employee receives a bonus of 10%, otherwise enter N");
    		if(input.nextLine().toLowerCase().contains("y")) {
    			bonusPay = true;
    		} else {
    			bonusPay = false;
    		}
    	} else if (	line.equals("hourly")) {
    		System.out.println("Enter hourly pay");
    		rate = input.nextDouble();
    		System.out.println("Enter # of hours");
    		hours = input.nextDouble();
     
    	}
    	Employee2 Employee1 = new Employee2(name, type, rate, hours, salary, bonusPay);
     
    	 System.out.println();
       	 System.out.println("\t  Name          Status              Hours             Rate             Weekly Pay Amount");
       	 System.out.println("\t======================================================================");
       	 System.out.println(Employee1.getName() +              Employee1.getType() +          Employee1.getHours()             + Employee1.getRate()         + Employee1.getWeeklyPay());
       	 System.out.println();
        }
     
    }
    When i execute it.
    --------------------Configuration: <Default>--------------------
    Hello! Welcome to Employee Database
    If Employee is salaried enter S. Otherwise enter H for hourly
    h

    it stays at this indefinitely, so there is something wrong with the if loops

  6. #6
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Symbol not found error

    That shouldn't even compile.
    } else if()) {
    Not only is the if statement empty, but there is an extra bracket.
    Furthermore:
    private string line;
    string should be a capital S: String
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. multiple annottions found error in jsp page with eclipse
    By sfdcmallik in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: May 9th, 2012, 08:40 PM
  2. string identifier symbol not found
    By MeteoricDragon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 26th, 2012, 04:52 PM
  3. Remaining compile errors: no suitable method found for & cannot find symbol
    By ChuckLep in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2011, 03:33 PM
  4. [SOLVED] cannot find symbol error
    By Topflyt in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 5th, 2011, 08:57 AM
  5. Cannot find symbol ERROR
    By yacek in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 21st, 2011, 11:39 PM