package scannerinput;

import java.util.Scanner;

public class InputNumbers {
    
    public static void main(String[] args) {

        /*
         * Scanner is a class that models an input stream into your 
         * program. You can tell the Scanner to get inputs from a String, 
         * a file, or the keyboard (System.in).
         * To use a Scanner, you have to instantiate it.
         * In other words, you have to create a Scanner object based on 
         * the Scanner class. 
         * Then you can use the methods that belong to Scanner.
         * These methods are non-static methods: you can only invoke or 
         * execute these methods on an object, not on the class.
         * e.g. Math methods are static: you invoke them using the name 
         * of the class, such as Math.pow() or Math.sqrt().
         * 
         * Popular Scanner methods:
         * nextInt() - reads in characters from the keyboard and returns them
         *     as an int.
         * nextDouble() - reads in characters from the keyboard and returns 
         *     them as a double.
         * nextBoolean() - reads in characters from the keyboard and returns
         *     them as a boolean.
         * nextLine() - reads in characters from the keyboard and returns
         *     them all as a String
         * next() - reads in characters from the keyboard up to the first 
         *     whitespace character (tab, space, newline/Enter) and returns 
         *     them as a String
         */

        // creates a variable "in" that holds a scanner and gives that 
        // "in" variable a new Scanner object that will read inputs from 
        // the System.in (keyboard) object
        Scanner in = new Scanner(System.in);

        System.out.print("Enter quantity: ");

        // Execute the scanner object's nextInt() method.
        // This reads in any keystrokes from the INPUT BUFFER, converts
        // them to the int data type, and returns that int result.
        int qty = in.nextInt();

        System.out.print("Enter price: ");
        
        // Execute the scanner object's nextDouble() method.
        // This reads in any keystrokes from the INPUT BUFFER, converts 
        // them to the double data type, and returns that double result.
        double price = in.nextDouble();

        in.close();  // always close when finished!!

        // calculate and display the total
        double total = price * qty;
        System.out.printf("Total: $%.2f\n", total);

        
    }
}
