// 10/30/2019

/* We are hired by a company that sells carpets to
 * write software that gives customers estimates.
 *
 * The program reads in length and width of a room.
 * It gives the customer a choice of carpet types with 
 * price per square foot of each type.
 * Program reads in customer's choice and prints
 * the estimated price for carpeting the room.
 */
import java.util.Scanner;

// OUR PURPOSE IS TO PRACTICE WRITING METHODS
public class Carpet {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    final double TYPE1 = 5.5;
    final double TYPE2 = 16.75;
    final double TYPE3 = 19.55;
     
    // read in length and width
    double length = readDouble(sc, "Enter length: ");
    double width = readDouble(sc, "Enter width: ");
    // calculate square footage
    int sqrft = calculateSqrFt(length, width);
    System.out.println("length: " + length +
                       " width: " + width +
                       " sqr footage: " + sqrft);
    // get carpet choice
    int choice = carpetMenu(sc, TYPE1, TYPE2, TYPE3);
    System.out.println("choice: " + choice);
    double pricePerSqrFt = 0;
    switch(choice) {
      case 1:  pricePerSqrFt = TYPE1;
      break;
      case 2:  pricePerSqrFt = TYPE2;
      break;
      case 3:  pricePerSqrFt = TYPE3;
      break;
      default: System.out.println("that is not a valid choice.");
    }
    // figure out estimated price
    double estimate = calculatePrice(sqrft, pricePerSqrFt);
    // print estimate
    System.out.println("Estimated price is " + estimate);
  }
  /** @param scanner is the Scanner object used for reading
    * @param msg is used to prompt user
    * @return the double value read in
    */
  public static double readDouble(Scanner scanner, String msg) {
    System.out.println(msg);
    // input validation using a while loop
    while (!scanner.hasNextDouble()) {
      System.out.println("something is wrong with the input" 
                        + " skipping line... ");
      scanner.nextLine(); // skip line
      System.out.println(msg);
    }
    return scanner.nextDouble();
  }
  /** calculateSqrFt accepts 2 doubles, takes
    * their ceilings, and returns the product
    * of ceilings
    */
  public static int calculateSqrFt(double l, double w){
    return (int)Math.ceil(l)*(int)Math.ceil(w);
  }

  public static int carpetMenu(Scanner scanner, final double TYPE1,
  final double TYPE2, final double TYPE3) {
    System.out.println("1: Type 1 $ " + TYPE1 + "\n" +
                       "2: Type 2 $ " + TYPE2 + "\n" +
                       "3: Type 3 $ " + TYPE3 +"\n" +
                       "Enter 1,2, or 3: ");
    return scanner.nextInt();
  } 
  public static double calculatePrice(int sqrft, double pricePerSqrFt) {
    return sqrft * pricePerSqrFt;
  }
}