Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab #8 Program 3 – Gift Box Class and Client Program (give you more practice) –

ID: 3914948 • Letter: L

Question

Lab #8 Program 3 – Gift Box Class and Client Program (give you more practice) – 15 pts

Step 1: Design a

GiftWrap

class

Design (using a UML) a

GiftWrap

class that a gift wrapping store could use to calculate the price of

wrapping rectangular gift boxes and generate invoices/receipts for their customers. The class will

allow a gift wrapping store to calculate the cost of wrapping various sized rectangular boxes. The class

will have member functions to calculate the price of the gift wrap box being wrapped, tax on the gift

wrap sold, and the total cost of the gift wrap both including and excluding tax.

The class should have the following member variables:

?

length

– this variable holds the length of the box in inches

?

width

– this variable holds the width of the box in inches

?

height

– this variable holds the height of the box in inches

?

taxRate

–this variable holds the sales tax rate for the company

?

pricePerInch

– this variable holds the price per inch of the gift wrap

The class should have the following member functions:

?

Two Constructors:

o

One constructor should be a no argument (no arg) constructor. This constructor should set the

length, width and height

member variables to 1.0, the

pricePerInch

member variable to 0.036,

and the

taxRate

member variable to 0.08.

o

One constructor that accepts the following

two

values as arguments (so the constructor should

have two parameter variables) and assigns them to the appropriate member variables: the tax

rate and the price per inch. This constructor should set the

length, width and length

member

variables to 1.0.

?

Do not allow the

pricePerInch

member variable to be set to numbers less than zero.

Use reasonable default values. It’s up to you to know how to design this based on class

lecture on object oriented programming.

?

Do not allow the

taxRate

member variable to be set to a number less than zero or

greater than one. Use reasonable default values. It’s up to you to know how to design

this based on class lecture on object oriented programming.

?

Five Set Functions:

o

Design a set function for each member variable:

length, width, height, pricePerInch,

and

taxRate

.

?

Do not allow the

length, width, height

, and

pricePerInch

member variables to be

set to numbers less than zero. It’s up to you to know how to design this based

on class lecture on object oriented programming.

?

Do not allow the

taxRate

member variable to be set to a number less than zero or

greater than one. It’s up to you to know how to design this based on class

lecture on object oriented programming.

.

?

Five Get Functions:

o

Design get function for each member variable:

length, width, height, pricePerInch,

and

taxRate

o

It’s up to you to know how to design these functions based on class lecture on object oriented

programming.

?

calcSubtotal

Member Function:

o

This member function should calculate the price of the gift wrap BEFORE tax. The price of the

gift wrap before tax is calculated as follows:

1. First calculate the surface area of the box.

o

Surface Area = (2 * length * width) + (2 * length * height) + (2 * width * height)

2. Next multiply the surface area of the box by the price per inch. This is the subtotal for the

gift wrap.

?

calcTax

Member Function:

o

This member function should calculate the tax on the gift. The tax is the subtotal * the tax rate.

Be efficient and use existing functions if you can.

?

calcTotal

Member Function:

o

This member function should calculate the overall total price of the gift wrap which is the

subtotal + the tax. Be efficient and use e

Explanation / Answer

Since you have not provided the language of your preference, I am providing the code in Java.

CODE

===============

public class GiftWrap {

   private double length, width, height;

   private double taxRate, pricePerInch;

  

   public GiftWrap() {

       length = width = height = 1.0;

       pricePerInch = 0.036;

       taxRate = 0.08;

   }

   public GiftWrap(double taxRate, double pricePerInch) {

       this.length = 1.0;

       this.width = 1.0;

       this.height = 1.0;

       if(taxRate < 0 || taxRate > 1) {

           this.taxRate = 0.08;

       } else {

           this.taxRate = taxRate;

       }

      

       if(pricePerInch < 0) {

           this.pricePerInch = 0.036;

       } else {

           this.pricePerInch = pricePerInch;

       }

   }

   /**

   * @param length the length to set

   */

   public void setLength(double length) {

       if(length < 0) {

           this.length = 1.0;

           return;

       }

       this.length = length;

   }

   /**

   * @param width the width to set

   */

   public void setWidth(double width) {

       if(width < 0) {

           this.width = 1.0;

           return;

       }

       this.width = width;

   }

   /**

   * @param height the height to set

   */

   public void setHeight(double height) {

       if(height < 0) {

           this.height = 1.0;

           return;

       }

       this.height = height;

   }

   /**

   * @param taxRate the taxRate to set

   */

   public void setTaxRate(double taxRate) {

       if(taxRate < 0 || taxRate > 1) {

           this.taxRate = 0.08;

           return;

       }

       this.taxRate = taxRate;

   }

   /**

   * @param pricePerInch the pricePerInch to set

   */

   public void setPricePerInch(double pricePerInch) {

       if(pricePerInch < 0) {

           this.pricePerInch = 0.036;

           return;

       }

       this.pricePerInch = pricePerInch;

   }

   /**

   * @return the length

   */

   public double getLength() {

       return length;

   }

   /**

   * @return the width

   */

   public double getWidth() {

       return width;

   }

   /**

   * @return the height

   */

   public double getHeight() {

       return height;

   }

   /**

   * @return the taxRate

   */

   public double getTaxRate() {

       return taxRate;

   }

   /**

   * @return the pricePerInch

   */

   public double getPricePerInch() {

       return pricePerInch;

   }

  

   public double calcSubtotal() {

       double area = (2 * length * width) + (2 * length * height) + (2 * width * height);

       return area * pricePerInch;

   }

  

   public double calcTax() {

       return taxRate * calcSubtotal();

   }

  

   public double calcTotal() {

       return calcSubtotal() + calcTax();

   }

}