Basic Java problem...HELP ME!

Discussion in 'Programming & Scripting' started by TiNd3r, Nov 30, 2008 with 4 replies and 244 views.

  1. TiNd3r

    TiNd3r Retired Retired

    Messages:
    1,943
    Ratings:
    521
    I'm new to java, I hate it but I guess the more I get help, the better I'll become.


    Whats up with this stupid problem? I don't get it, the program compiles fine on the school computers yet when i load it up on my laptop i get this stupid error !!!

    Code:
    Compiling I:\Multimedia Technology\CSCI1402\Coursework\BMI_IF_STATEMENT.java
    The current directory is: I:\Multimedia Technology\CSCI1402\Coursework
    Command line: "C:\Program Files\Java\jdk1.6.0_10\bin\javac.exe" -deprecation -g -classpath I:\MULTIM~1\CSCI1402\COURSE~1  "I:\Multimedia Technology\CSCI1402\Coursework\BMI_IF_STATEMENT.java"
    I:\Multimedia Technology\CSCI1402\Coursework\BMI_IF_STATEMENT.java:14: cannot find symbol
    symbol  : variable keyBoardIn
    location: class BMI_IF_STATEMENT
    char option  = keyBoardIn.readChar();
    ^
    I:\Multimedia Technology\CSCI1402\Coursework\BMI_IF_STATEMENT.java:24: cannot find symbol
    symbol  : variable keyBoardIn
    location: class BMI_IF_STATEMENT
    metricWeight = keyBoardIn.readDouble();
    ^
    I:\Multimedia Technology\CSCI1402\Coursework\BMI_IF_STATEMENT.java:27: cannot find symbol
    symbol  : variable keyBoardIn
    location: class BMI_IF_STATEMENT
    metricHeight = keyBoardIn.readDouble();
    ^
    I:\Multimedia Technology\CSCI1402\Coursework\BMI_IF_STATEMENT.java:38: cannot find symbol
    symbol  : variable keyBoardIn
    location: class BMI_IF_STATEMENT
    imperialWeight = keyBoardIn.readDouble();
    ^
    I:\Multimedia Technology\CSCI1402\Coursework\BMI_IF_STATEMENT.java:41: cannot find symbol
    symbol  : variable keyBoardIn
    location: class BMI_IF_STATEMENT
    imperialHeight = keyBoardIn.readDouble();
    ^
    5 errors
    Finished
    
    Here is the original coding.

    Code:
    /*
    * Author: p08297236
    * Created: 28 November 2008 15:32:17
    * Modified: 28 November 2008 15:32:17
    */
    
    
    public class BMI_IF_STATEMENT
    {
    public static void main(String args[])
    {
    
    System.out.println("I or M");
    char option  = KeyBoardIn.readChar();
    
    double metricWeight, imperialWeight;
    double metricHeight, imperialHeight;
    double metricBMI, imperialBMI;
    
    
    if (option == 'M')
    {
    System.out.println("Please enter your weight");
    metricWeight = KeyBoardIn.readDouble();
    
    System.out.println("Please enter your height");
    metricHeight = KeyBoardIn.readDouble();
    
    metricBMI = metricWeight / (metricHeight * metricHeight);
    System.out.println("Your Body Mass Index is "+ metricBMI);
    }
    
    
    
    if (option == 'I')
    {
    System.out.println("Please enter your weight");
    imperialWeight = KeyBoardIn.readDouble();
    
    System.out.println("Please enter your height");
    imperialHeight = KeyBoardIn.readDouble();
    
    imperialBMI = (imperialWeight * 703) / (imperialHeight * imperialHeight);
    System.out.println("Your Body Mass Index is "+ imperialBMI);
    }
    
    }
    
    }
    
    
    
    
    
    Any help would be appreciated


    THANKS
     
  2. Luxurious Meat

    Luxurious Meat Getting There

    Messages:
    615
    Ratings:
    120
    The symbol 'KeyBoardIn' is not declared.
     
  3. confused5

    confused5 Enthusiast

    Messages:
    766
    Ratings:
    75
    Use java.util as your scanner, KeyBoard is not declared by anything. Try this
    Code:
    /*
    * Author: p08297236
    * Created: 28 November 2008 15:32:17
    * Modified: 28 November 2008 15:32:17
    */
    
    [B]import java.util.Scanner;[/B]
    
    public class BMI_IF_STATEMENT
    {
    public static void main(String args[])
    {
    [B]Scanner KeyBoardIn = new Scanner(in)[/B];
    System.out.println("I or M");
    char option  = KeyBoardIn.readChar();
    
    double metricWeight, imperialWeight;
    double metricHeight, imperialHeight;
    double metricBMI, imperialBMI;
    
    
    if (option == 'M')
    {
    System.out.println("Please enter your weight");
    metricWeight = KeyBoardIn.readDouble();
    
    System.out.println("Please enter your height");
    metricHeight = KeyBoardIn.readDouble();
    
    metricBMI = metricWeight / (metricHeight * metricHeight);
    System.out.println("Your Body Mass Index is "+ metricBMI);
    }
    
    
    
    if (option == 'I')
    {
    System.out.println("Please enter your weight");
    imperialWeight = KeyBoardIn.readDouble();
    
    System.out.println("Please enter your height");
    imperialHeight = KeyBoardIn.readDouble();
    
    imperialBMI = (imperialWeight * 703) / (imperialHeight * imperialHeight);
    System.out.println("Your Body Mass Index is "+ imperialBMI);
    }
    
    }
    
    }
    
     
  4. OP
    TiNd3r

    TiNd3r Retired Retired

    Messages:
    1,943
    Ratings:
    521
    yeh i later figured out that it is my JDK and some sort of class file messing things up.

    How would i rectify the problem because it is doing it for every java file not just this 1 :frown:
     
  5. confused5

    confused5 Enthusiast

    Messages:
    766
    Ratings:
    75
    Make sure you downloaded the right JDK. I can send you instructions if you need help with that and the classpath and everything.

    Can you post some of the exact code from a program that compiles and runs in school? My guess is that you're creating an instance of a class that is somewhere in your computer at school but you don't have it on your home computer