FeetInchConvert - // What happens if the constant is not a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// File: FeetInchConvert.java // Course: CSC 211 // Author: Amber Settle // Purpose: Application to prompt for a number of feet and convert // to inches, and then prompt for a number of inches and // convert to feet. // All input is done using the Scanner class (a Java 1.5 feature). / import java.util.Scanner; i public class FeetInchConvert { //static Scanner ourScanner = new Scanner(System.in); / // Prompt for feet and convert to inches. // Next, prompt for inches and convert to feet. // Can we put the constant outside of main? // Why would we put the constant outside of main? / public static void main(String[] args) { final double INCHES_IN_FOOT = 12.0; // What happens if I modify INCHES_IN_FOOT in the program? // Why did I make this constant a double?
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // What happens if the constant is not a double? / double feet, inches; int wholeInches; i Scanner ourScanner = new Scanner(System.in); S // What happens here if the user types in an integer value? System.out.print("Enter a number in feet: "); feet = ourScanner.nextDouble(); f inches = feet * INCHES_IN_FOOT; i System.out.println("\n" + feet + " feet is " + inches + " inches.\n"); S // What happens here if the user types in a decimal value? System.out.print("Now, enter a whole number in inches: "); wholeInches = ourScanner.nextInt(); w feet = wholeInches / INCHES_IN_FOOT; f System.out.println("\n" + wholeInches + " inches is " + feet + " feet.\ n"); n } }...
View Full Document

This note was uploaded on 03/05/2011 for the course CSCI 384 taught by Professor Drchan during the Spring '11 term at CA Health Sciences.

Ask a homework question - tutors are online