/* Program: Carpet.java * Author: Dr. Blaise Liffick * Date: Sept. 20, 2007 * Class: CS 161-01 * * This program calculates the amount of carpet needed for a * rectangular room. */ import java.util.Scanner; public class Carpet { public static final double INCHES_IN_FOOT = 12.0; public static final double SQ_FT_IN_YARDS = 9.0; public static void main(String[] args) { int lengthFt; // the input feet part of the length as an integer int lengthIn; // the input inches part of the length as an integer int widthFt; // the input feet part of the width as an integer int widthIn; // the input inches part of the width as an integer double area; // the are of the carpet needed in square yards Scanner input = new Scanner(System.in); instructions(); System.out.print("Please enter length feet: "); lengthFt = input.nextInt(); System.out.println(); System.out.print("Please enter length inches: "); lengthIn = input.nextInt(); System.out.println(); System.out.print("Please enter width feet: "); widthFt = input.nextInt(); System.out.println(); System.out.print("Please enter width inches: "); widthIn = input.nextInt(); area = ((lengthFt + lengthIn / INCHES_IN_FOOT) * (widthFt + widthIn / INCHES_IN_FOOT)) / SQ_FT_IN_YARDS; System.out.println(); System.out.println("For a room that is " + lengthFt + " feet, " + lengthIn + " inches by " + widthFt + " feet, " + widthIn + " inches, you will need " + area + " square yards of carpet."); } public static void instructions() { System.out.println("This program calculates the amount of carpet"); System.out.println("needed for a rectangular room. You will be"); System.out.println("asked to enter the length of the room in feet"); System.out.println("and inches (as integers), then the width in feet"); System.out.println("and inches. The program will then output the"); System.out.println("number of square yards of carpet needed."); System.out.println(); } }