Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

import java.Scanner; public class UserInput { //TO DO: Define promptForInt here //TO DO: Define promptForDouble here //TO DO:

import java.util.Scanner;

public class UserInput {

  //TO DO: Define promptForInt here

  //TO DO: Define promptForDouble here

  //TO DO: Define promptForYesNo here

  public static void main(String[] args) { 

    Scanner sc = new Scanner(System.in);

    //All values are initialised so code will compile and run

    int guess = -1;    //user's guess (between 1 and 10)

    double percent = -1;  //a percentage (as a value between 0 and 1)

    boolean again = false; //do they want to go again?

    System.out.println("Testing prompt for int... the number should be saved in guess.");

    System.out.println(" - Enter '60' -- should loop with error");

    System.out.println(" - Enter '-6' -- should loop with error");

    System.out.println(" - Enter '6' and it should work");

    // guess = promptForInt(sc, "Enter a number", 1, 10);

    System.out.println("Guess: " + guess);

    System.out.println();

    System.out.println("Testing prompt for double... the number should be saved in percent.");

    System.out.println(" - Enter '60' -- should loop with error");

    System.out.println(" - Enter '-1' -- should loop with error");

    System.out.println(" - Enter '0.5' and it should work");

    // percent = promptForDouble(sc, "Enter percent value", 0.0, 1.0);

    System.out.println("Percent: " + percent);

    System.out.println();

    System.out.println("Testing prompt for yes/no... the result is saved in again.");

    System.out.println(" - Extend these boolean tests... add messages and verify your solution!");

    System.out.println(" - Enter 'yes' and it should succeed");

    // again = promptForYesNo(sc, "Play again?");

    System.out.println("Again: " + again);

    System.out.println();

    System.out.println(" - Verify that it can also read in false...");

    // again = promptForYesNo(sc, "Play again?");

    System.out.println("Again: " + again);

    System.out.println();

    System.out.println("Tests complete...");     

  }

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question