{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

FeetInchConvert

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

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

// 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?
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(&amp;quot;Enter a number in feet: &amp;quot;); feet = ourScanner.nextDouble(); f inches = feet * INCHES_IN_FOOT; i System.out.println(&amp;quot;\n&amp;quot; + feet + &amp;quot; feet is &amp;quot; + inches + &amp;quot; inches.\n&amp;quot;); S // What happens here if the user types in a decimal value? System.out.print(&amp;quot;Now, enter a whole number in inches: &amp;quot;); wholeInches = ourScanner.nextInt(); w feet = wholeInches / INCHES_IN_FOOT; f System.out.println(&amp;quot;\n&amp;quot; + wholeInches + &amp;quot; inches is &amp;quot; + feet + &amp;quot; feet.\ n&amp;quot;); n } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online