Java AQA console 2014

How do I ask the user for a double/boolean data type input in Java AQAconsole 2014?

//For example:
double brightness = 0.0;
brightness = console.readLine("Please enter low brightness level: ");

//I have also tried readInteger... 
brightness = console.readInteger("Please enter low brightness level: ");

//Please check the link for the template files I have in AQAconsole. Any help will be greatly appreciated. Thanks.

Hi @Semicode welcome to the community and thank you for your question.

I’ve not used AQAconsole 2014 before. Can you please explain what it is?

It’s a template we create for students in schools to use Java. Pretty much the same but a bit easier, as instead of System.out.println, we write console.writeLine - when it’s a String; or console.readLine if we want to ask the user to input String data.

1 Like

Thank you for that information!

I’m not sure if this is the AQA way (you might have to check this with teachers who deliver this course) but I’ve added some lines to your program so that string inputs are recast as doubles or booleans as appropriate.

    AQAConsole console = new AQAConsole();

    public Main() {
        String name;
        name = console.readLine("Please enter your name ");
        console.writeLine("Hello "+name);

        double brightness = 0.0;
        String temp;
        temp = console.readLine("Please enter low brightness level: ");
        brightness = Double.parseDouble(temp);
        console.writeLine("Brightness level: "+brightness);

        boolean lighton;
        temp = console.readLine("Please enter if light is on(True) or off(False): ");
        lighton = Boolean.parseBoolean(temp);
        console.writeLine("Light on? "+lighton);
1 Like

Ian, thank you so much for this piece of code, it works in AQA.console!
I will pass it on to my team.
Is there anywhere where I can give you kudos?

1 Like

That’s great to hear @Semicode !

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.