import java.util.Scanner; import java.util.*; /** * This class is written for a Carpet Company to calculate the * price of a carpet for a room. */ public class CarpetCo { /** * Give user a choice of carpets and get price * Read in length and width of room * Calculate area (making sure to round up the numbers) * Calculate price */ public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); double pricePerSqFt = chooseType(keyboard); if (pricePerSqFt==-1) System.exit(1); System.out.println("Price per square foot is: " + pricePerSqFt); double length = readDouble("length", keyboard); double width = readDouble("width", keyboard); int area = area((int)Math.ceil(length), (int)Math.ceil(width)); System.out.println("length: " + length + " width: " + width + " area: " + area + " price: $" + calculatePrice(area, pricePerSqFt)); } /** * This method prints a menu of different carpet choices. * @param Scanner object to read choice * @return price per square foot of the user's choice of carpet */ public static double chooseType (Scanner sc) { // menu System.out.printf("1. $5.00 per sq ft\n2. $7.00 per sq ft\n3." + "$10.00 per sq ft.\nEnter choice (1-3): "); // validate input... next version switch (sc.nextInt()) { case 1: return 5.0; case 2: return 7.00; case 3: return 10.0; default: System.out.println("Your choice is not valid!"); } return -1; } /** */ public static double readDouble(String prompt, Scanner sc) { System.out.print("Enter the " + prompt + ":"); // d is a local variable double d = sc.nextDouble(); return d; } /** */ public static int area(int w, int len) { return w*len; } /** * calculatePrice calculates and returns price to carpet a room * @param area is the rounded area of the room as an int * @param price is the price per square foot of the carpte * @return the total price for the room */ public static double calculatePrice(int area, double price) { return area*price; } } /**LAB10: Write a method that accepts a temperature in degrees * Celcius and returns the degrees Faranheit. * Test the method by reading in several values in main (hint: use * a loop) and calling and printing the return value. * NOTE: all reading and printing should be done in main. */