Walle22
Walle22

Reputation: 1

I keep getting a error saying cannot find symbol - variable keyboard

  import javax.swing.JOptionPane;
  import java.io.File;
  import java.util.Scanner;
  public class Map{
  public static void main(String[] args){ 

  // create a Scanner object 
  Scanner input = new Scanner(System.in);

 //Prompt the user to enter three numbers in inches 
 System.out.print("enter four numbers:");
 double distance1 = input.nextDouble();
 double distance2 = input.nextDouble();
 double distance3 = input.nextDouble();
double distance4 = input.nextDouble();

 //public classify DistanceScale

    //Make a constant to hold kilometers to miles conversion
    //final const MILESTOKILOS = 1.609344;

    // Explain the program to the user
    System.out.println("Welcome! This program calculates true distance from map measurements You can enter up to 4 distances");
    System.out.println();

    // ask user for 4 distances, from the map.
    System.out.print("Enter distance 1 (in inches): ");
    double distancel = keyboard.nextdouble();

    System.out.print("Enter distance 2 (in inches): "); 
    double distance2 = keyboard.nextdouble();        

    System.out.print = "Enter distance 2 (in inches): ";
    double distance3 = keyboard.nextdouble();

    // determine total miles from total inches
    // Scale:  1 inch is 1/4 mile
    double totalMiles = totalInches * 1/4;        
    // add to get total inches on map
    distance1 + distance2 + distance2 + distance4 = totalInches;

    //round to one-tenth of a mile 
    int miles =(totalMiles + 0.05) * 10;

    //total miles
    int totalMiles = 10%

    // calculate kilometers
    totalKilos = totalMiles * miles * kilos;

    // round kilometers to tenths
    //int class kilos = totalKilos + {005 * 10)};
    //totalKilos = kilos / 100;

    // print results
    System.out.printn("Total inches:     " + "totalInches");
    Sytem.out.println ("Total miles:      " + milesTotal);
    System.out.prntln("Total kilometers: totalKilos");
    {
    }

I keep getting a error on all my double distancel = keyboard.nextdouble(); I'm new to java, and I'm using a program called bluej. I don't understand why its saying keyboard needs to be a variable. If you guys can help me with this error that will be great. I always like to learn. Thanks!

Upvotes: 0

Views: 1459

Answers (2)

gkrls
gkrls

Reputation: 2664

Your Scanner is called input and not keyboard you should change that when calling it here for example:
double distancel = keyboard.nextdouble(); change it to double distancel = input.nextdouble();.

I also see another thing:

totalKilos = totalMiles * miles * kilos;

You don't have any declared variable totalKilos to assign it this value.

You should int totalKilos = totalMiles * miles * kilos;

Same thing here: distance1 + distance2 + distance2 + distance4 = totalInches;

I think you want to do double totalInches = distance1 + distance2 + distance2 + distance4;

Upvotes: 0

Pr0gr4mm3r
Pr0gr4mm3r

Reputation: 6230

You are trying to reference a variable which is not declared, that's why the compiler says he cannot find keyboard.

Just replace all your keyboard references with input.

Seems like either a typo or a copy&paste error.

Upvotes: 1

Related Questions