/**
 * 
 */
package examples;

import java.io.Console;

/**
 * A program that demonstrates reading in from the console, using calculating
 * the area of a rectangle as the example.
 * 
 * Does not work within an IDE directly--have to run from a terminal.
 * 
 * Note that this class does not have the error checking that
 * ConsoleUsingScannerDemo has.
 * 
 * @author Sara Sprenkle
 */
public class ConsoleUsingConsoleDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out
				.println("This program calculates the area of a rectangle.\n");

		Console console = System.console();
		if (console == null) {
			System.err.println("No console.");
			System.exit(1);
		}

		// prompt the user for the width
		String widthPrompt = "Please enter the width of a rectangle (as an integer): ";

		// check for bad input, read in the integer representing the width
		String widthLine = console.readLine(widthPrompt);

		int width = Integer.parseInt(widthLine);

		// prompt the user for the height
		String heightPrompt = "Please enter the height of a rectangle (as an integer): ";

		// check for bad input, read in the integer representing the width
		String heightLine = console.readLine(heightPrompt);

		int height = Integer.parseInt(heightLine);

		/*
		 * scan.close();
		 */
		int area = height * width;

		System.out.println("The area of your rectangle is " + area + ".");
	}

}
