/* An example of non-void methods: 1. a method that asks the user to enter a measurement in feet and returns it. 2. a method that takes as argument a measurement in feet, converts it to inches, and returns this value. Laura Toma csci 107 */ public class Feet2Inches{ final static double INCHES_PER_FOOT = 12.0; static ReadStream r; public static void main (String args[]) { r = new ReadStream(); //explain program to user explainProgram(); //get measurement in feet double measurementInFeet = getFeet(); //calculate the measurement in inches double measurementInInches = convertFeetToInches(measurementInFeet); //output both measurements outputResults(measurementInFeet, measurementInInches); } //end of main /* this method describes the program to the user */ public static void explainProgram() { System.out.println("This program will convert a measurement in feet to inches."); } //end of explainProgram /* This method asks the user to enter a measurement in feet and * returns this value. It ensures that the returned value is * positive. That is, if the user enters something negative, it * keeps asking to re-enter until the value is positive. */ public static double getFeet() { double numFeet; System.out.print("enter feet: "); numFeet = r.readDouble(); r.readLine(); while (numFeet < 0.0) { System.out.print("must be positive, please re-enter: "); numFeet = r.readDouble(); r.readLine(); } return numFeet; } //end of getFeet /* this method takes as argument a measurement in feet, converts * it in inches and returns it */ public static double convertFeetToInches(double measurementInFeet) { double measurementInInches = measurementInFeet * INCHES_PER_FOOT; return measurementInInches; } //end of convertFeetToInches /* this method takes as arguments two double variables, the first one represents a measurement in feet, and the second one a measurement in inches. It prints the two measurements. */ public static void outputResults(double localFeet, double localInches) { System.out.println("the measurement in feet is: " + localFeet); System.out.println("the measurement in inches is: " + localInches); System.out.println("Bye!"); } //end of outputResults } // end of class