Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Java help! cannot find symbol

  1. #1
    stephanie904 is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Java help! cannot find symbol

    Hi!..im getting cannot find symbol when i try to compile the file and it gives 7 errors...not sure what i am doing wrong...please help me


    HealthProfileTest.java:41: cannot find symbol
    symbol : variable Convert
    location: class HealthProfileTest
    double pHeight = Convert.ToDouble(in.nextLine());



    Java Code:
    import java.util.Scanner;
    import javax.swing.*;
    
    
    
    public class HealthProfileTest
    {
    	public static void main(String[] args) 
    	{
    
    
    		// Welcome message
    		Scanner in = new Scanner(System.in);
    		System.out.println("Welcome to the Health Profile!");
    		System.out.println("Please enter your information when prompted.\n");
    
    		
    
    		
    		// Promt and obtain user input
    		System.out.println("First name: ");
          String fName = in.nextLine();
    		
    		System.out.println("Last name: ");
    		String lName = in.nextLine();
    		
    		System.out.println("Gender: ");
    		String pGender = in.nextLine();
    		
    		System.out.println("Year of birth: ");
    		int year = Convert.ToInt32(in.nextLine());
    		
    		System.out.println("Month of birth: ");
    		int month = Convert.ToInt32(in.nextLine());
    		
    		System.out.println("Day of birth: ");
    		int day = Convert.ToInt32(in.nextLine());
    		
    		System.out.println("Height in meters: ");
    		double pHeight = Convert.ToDouble(in.nextLine());
    		
    		System.out.println("Weight in kilos: ");
    		double pWeight = Convert.ToDouble(in.nextLine());
    		
    		// Create a HealthProfile object
    		HealthProfile myHealthProfile = new HealthProfile(fName, lName, pGender, year, 
    		                                                  month, day, pHeight, pWeight);
    		
    		// Print the information from object myHealthProfile
    		System.out.println("\nInformation inserted to your health profile:");
    		System.out.println("Name: \t\t\t{0} {1}", myHealthProfile.FirstName, myHealthProfile.LastName);
    		System.out.println("Gender: \t\t{0}", myHealthProfile.Gender);
    		System.out.println("Date of birth: \t\t{0}-{1:00}-{2:00}", 
    		                  myHealthProfile.BirthYear, myHealthProfile.BirthMonth, myHealthProfile.BirthDay);
    		System.out.println("Height: \t\t{0}", myHealthProfile.Height);
    		System.out.println("Weight: \t\t{0}", myHealthProfile.Weight);
    		
    		// Call method PersonAge to calculate the persons age
    		System.out.println("\nWe will now print out your age, BMI, maximum heart " +
    			"rate \nand target heart rate range:");
    		System.out.println("Your age: \t\t\t{0}", myHealthProfile.PersonAge());
    		System.out.println("Your BMI: \t\t\t{0}", myHealthProfile.BodyMassIndex());
    		System.out.println("Your maximum heart rate: \t{0}", myHealthProfile.MaxRate());
    		System.out.println("Your target heart rate range: \t{0} to {1}", myHealthProfile.MinTarget(), myHealthProfile.MaxTarget());
    		
    		System.out.println ("\n\nBMI VALUES\nUnderweight:\tless than 18.5\nNormal:\tbetween 18.5 and 24.9");
    		System.out.println ("\nUnderweight:\tless than 18.5");
    		System.out.println ("Normal:\t\tbetween 18.5 and 24.9");
    		System.out.println("Overweight:\tbetween 25 and 29.9");
    		System.out.println ("Obese:\t\tbetween 30 or greater");
    	}
    
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Java help! cannot find symbol

    Where is Convert defined?
    It's not in this class, or any import...

  3. #3
    stephanie904 is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Re: Java help! cannot find symbol

    so you are saying that Im missing Convert in here ??? not sure what you mean

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Java help! cannot find symbol

    You can't just make up things in Java.
    A Convert class or a variable called Convert that is of a class that has the methods you are calling needs to exist.
    So, where is it?
    That's what the compiler is asking.

  5. #5
    stephanie904 is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Re: Java help! cannot find symbol

    it is right here

    int year = Convert.ToInt32(in.nextLine());

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java help! cannot find symbol

    Quote Originally Posted by stephanie904 View Post
    it is right here

    int year = Convert.ToInt32(in.nextLine());
    No, it's not. You're trying to use a Convert class in that line, but this does not mean that you have a Convert class to use somewhere. Again, you can't make stuff up and hope it will work. You either are missing some library from your instructor or your assumptions on how Java works are way off and you'll need to check out the introductory tutorials.
    Tolls likes this.

Similar Threads

  1. cannot find symbol, (java:5)
    By simco99 in forum New To Java
    Replies: 2
    Last Post: 01-18-2012, 08:26 PM
  2. FileRead.java:79: cannot find symbol
    By xx__rose in forum New To Java
    Replies: 1
    Last Post: 05-09-2010, 04:06 AM
  3. java:34:cannot find symbol
    By MissyMadi in forum New To Java
    Replies: 5
    Last Post: 11-09-2008, 06:53 PM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •