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());
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");
}
}
Re: Java help! cannot find symbol
Where is Convert defined?
It's not in this class, or any import...
Re: Java help! cannot find symbol
so you are saying that Im missing Convert in here ??? not sure what you mean
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.
Re: Java help! cannot find symbol
it is right here
int year = Convert.ToInt32(in.nextLine());
Re: Java help! cannot find symbol
Quote:
Originally Posted by
stephanie904
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.