// Determine the cost to carpet a room when given the measurements
// and the cost per square yard.

import java.util.*;

public class CarpetLab {

	public static void main ( String[] args ) {
		Scanner scan = new Scanner ( System.in );

		// variable declarations
		double myArea = 0.0;
		double numberOfYards = 0.0;
		double myLength = 0.0;
		double myWidth = 0.0;
		double cost = 0.0;

		boolean go = true;
		int choice = 0;

		while (go) {   //  start of  the loop
			//   input
			System.out.println("> Enter the length: ");
			myLength = scan.nextDouble();
			System.out.println("> Enter the  width: ");
			myWidth = scan.nextDouble();
			System.out.println("> Enter the cost per square yard: ");
			double costPerYard = scan.nextDouble();

			//calculations
			myArea = myLength * myWidth;

			numberOfYards = Math.ceil(myArea / 9);

			cost = costPerYard * numberOfYards;

			// output your information here
			System.out.println("  **  Aladin's  Carpets  **   ");
			System.out.println("  *************************   ");
			System.out.println("> | My length : " + myLength);
			System.out.println();
			System.out.println("> | My width : " + myWidth);
			System.out.println();
			System.out.println("> | My cost : " + cost);

			System.out.println("Enter 0 to Stop or 1 to Continue");
			choice = scan.nextInt();

			if (choice == 0) {
				go = false;
			} else if (choice == 1) {
				// Continues the loop over
			} else {
				System.out.print("ERR: " + choice);
				System.out.print(" is not a valid option; please enter a valid option. Starting over..");
				System.out.println();
			}
		}	System.out.println("Thank you! Have a fantastic day!"); // end of the while  loop
	} // end of main
}   // end of the lab

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: