-1

All I want it to do is read input typed by the user as double type, and then convert it to another number. I'm also aware the equation isn't complete, not worried about that right now, just want it to run. I don't understand what I have done wrong.

public class EuroShoe {


    public static void main(String[] args) {

        double
        footLength,
        euroSize;

        System.out.println("EUROPEAN SHOE SIZE");
        System.out.println("Enter the length of your foot in inches:");
        footLength = Keyboard.readDouble();     // line 25
        euroSize = (((footLength - 9) * 3 / 2) + 15);
        System.out.println("Your European shoe size is " + euroSize);
    }


}
daedsidog
  • 1,732
  • 2
  • 17
  • 36
StrawHat
  • 3
  • 2
  • In what context was this code? Did they create a custom class called `KeyBoard`? – GBlodgett Dec 09 '18 at 01:14
  • Also a [`Scanner`](https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html) is probably the easiest way to read from the console. (`Scanner in = new Scanner(System.in); footLength = in.nextDouble();`) – GBlodgett Dec 09 '18 at 01:15
  • There are essentially zero books from 1998 I would recommend now. – Dave Newton Dec 09 '18 at 01:17
  • ^this. On a side note, you should probably validate that the input is in fact numeric before trying to do math against it, otherwise it will inevitably fail. – user2366842 Dec 09 '18 at 01:17
  • This is the context, doesn't say anything about custom classes or anything, i just assumed it was like calling 'System'. – StrawHat Dec 09 '18 at 01:17
  • Tried the scanner code you gave me and it doesn't work either, doesn't recognize 'scanner', says 'cannot find symbol 'scanner'' – StrawHat Dec 09 '18 at 01:24

2 Answers2

0

This worked:

package euroshoe;

import java.util.Scanner;

public class EuroShoe {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("EUROPEAN SHOE SIZE");
        System.out.println("Enter the length of your foot in inches:");
        double footLength = input.nextDouble();
        double euroSize = (((footLength - 9) * 3 / 2) + 15);
        System.out.println("Your European shoe size is " + euroSize);
    }
}
pzaenger
  • 11,381
  • 3
  • 45
  • 46
StrawHat
  • 3
  • 2
0

If you are following a tutorial, please check on the imports that were mentioned. But to answer your question and make your program work here's an answer.

import java.util.Scanner

public class EuroShoe {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int i = 

        double footLength, euroSize;

        System.out.println("EUROPEAN SHOE SIZE");
        System.out.println("Enter the length of your foot in inches:");

        // The statement below calls the "scanner" object to get the user input of value "double"
        footLength = scanner.nextDouble();

        euroSize = (((footLength - 9) * 3 / 2) + 15);
        System.out.println("Your European shoe size is " + euroSize);
    }
}

Make sure to put this statement above

import java.util.Scanner // imports the specific Scanner class under the 'util' namespace

or you can use this as well

import java.util.* // imports every class under the 'util' namespace

Hope this helps you with your problem and keep coding! :)

arvicxyz
  • 381
  • 3
  • 13
  • 1
    About `import java.util.*;`: [Why is using a wild card with a Java import statement bad?](https://stackoverflow.com/questions/147454/why-is-using-a-wild-card-with-a-java-import-statement-bad) – pzaenger Dec 09 '18 at 01:52
  • 1
    My aim was to educate that there are other ways to import a Scanner. He/she will learn best practices over time and thanks for the link. :) – arvicxyz Dec 09 '18 at 01:57
  • 1
    I guess either way works in this case, but you should start with learning best practices, not learn them over time. – user2366842 Dec 12 '18 at 14:05
  • I disagree, it's easy for experienced programmers to say that. The point is he/she is still learning to code and eventually while learning to code he/she will learn of these best practices and learn them over time. There's a difference between learning over time and learning at a later time if that's how you've perceived it. :) – arvicxyz Dec 13 '18 at 03:23
  • You can't just start learning best practices without learning to code first right? How will you learn best practices on naming variables without knowing how to declare a variable first? :) – arvicxyz Dec 13 '18 at 03:24
  • Though this really isn't the place to argue it, I'll leave you with this - It's much easier to learn correctly the first time than to learn incorrectly and have to unlearn the wrong ways of doing things and re-learn something from scratch. That doesn't just go for programming either...that's ultimately the intent of pointing stuff like this out early on, so less re-work has to be done long term. – user2366842 Dec 14 '18 at 23:48
  • I rest my case. We have different point of views and if it worked for both of us then no problem about it. Thanks. – arvicxyz Dec 16 '18 at 01:17