Gifts And More is a store that offers giftwrapping for items

Gifts And More is a store that offers giftwrapping for items in rectangular shaped boxes. Customers can either buy standard wrapping paper or holiday wrapping paper. The owner of this store wants customers to be able to know how much they will spend on wrapping paper before they get to the counter in order to speed up the check out process. Standard wrapping paper costs $1 per square inch and holiday edition wrapping paper costs $2 per square inch. Customers are expected to enter measurements of the rectangular shaped box themselves. Example Program Run: ***Hello! Please pick from the following options:*** Buy standard wrapping paper-press 1 Buy holiday edition wrapping paper-press 2 1 You have selected standard wrapping paper. Please enter the size of your gift (in inches): Length: 2 Height: 5 Width: 4 You will pay $76 at the counter. Thank you for shopping with us!

Solution

The problem is to compute the cost required. If we look into any rectangular box we will notice that there are 6 faces.

Each face can be thought of as an 2D - rectangle and we know how to compute the area of 2D- rectangle (its length * breadth). Therefore for each of the 6 faces we compute the area of 2D- rectangle and add them up finally we multiply it with 2 if the gift wrapping is holiday edition as each square inch costs 2$;

Formula used:

cost = 2 * (length * height + length * width + height * width) * 1; // for standard wrapping

cost = 2 * (length * height + length * width + height * width) * 2; // for holiday edition.

Please find the Code below.

import java.util.Scanner;

public class GiftWrap {

   public static void main(String[] args) {

       boolean repeat = true;

       Scanner sc = new Scanner(System.in);

       int option = 0;

       long length, height, width, cost;

       while (repeat) {

           option = 0;

           while (option != 1 && option != 2) {

               System.out.println(\"***Hello! Please pick from the following options:***\");

               System.out.println(\"1) Buy standard wrapping paper press 1\");

               System.out.println(\"2) Buy holiday edition wrapping paper press 2\");

               option = sc.nextInt();

           }

           if (option == 1) {

               System.out.println(\"You have selected standard wrapping paper.\");

           } else {

               System.out.println(\"You have selected holiday edition paper.\");

           }

           System.out.println(\"Please enter the size of your gift(in inches):\");

           System.out.println(\"Enter Length:\");

           length = sc.nextInt();

           System.out.println(\"Enter Height:\");

           height = sc.nextInt();

           System.out.println(\"Enter Width:\");

           width = sc.nextInt();

           cost = 2 * (length * height + length * width + height * width) * option;

           System.out.println(\"You will pay $\" + cost + \" at the counter. Thanks You for shopping with us!\");

           System.out.println(\"Please Y or y to repeat or any other key to exit\");

           char ch = sc.next().charAt(0);

           if (ch != \'y\' && ch != \'Y\') {

               repeat = false;

           }

       }

   }

}

 Gifts And More is a store that offers giftwrapping for items in rectangular shaped boxes. Customers can either buy standard wrapping paper or holiday wrapping
 Gifts And More is a store that offers giftwrapping for items in rectangular shaped boxes. Customers can either buy standard wrapping paper or holiday wrapping

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site