ItemDiscountclassThe discount class is used to calculate the

ItemDiscountclass:The discount class is used to calculate the discount amount on a given sales item. The class has two instance variables:

discount: an integer value that represent the discount percent.For example, discount of 10 means 10% discount.

qualifiedQuantity: an integer value that represents the required quantity in order to apply the discount.The class has the following two methods:

A constructor to initialize the two instance variables

calculateDiscount: a method that takes one input of type SalesItemThe method checks whether the item is qualified for the discount or no. If the item is qualified, then the method returns a double valuethat represent amount of money to be deducted from the item. For example, assume the store would like to apply 10% discount if 5 or more copies of any item are sold together. To implement that, the following ItemDiscountobject created.

ItemDiscount d = new ItemDiscount(10,5);

For each sales item, i, the discount amount can be calculated as follows:

d.calcualteDiscount(i);

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

-----------------------------------------

OUTPUT:

Discount for 1 sales item = 0.0
Discount for 2 sales item = 0.0
Discount for 3 sales item = 0.0
Discount for 4 sales item = 0.0
Discount for 5 sales item = 0.0
Discount for 6 sales item = 10.0
Discount for 7 sales item = 10.0
Discount for 8 sales item = 10.0
Discount for 9 sales item = 10.0
Discount for 10 sales item = 10.0

ItemDiscountclass:The discount class is used to calculate the discount amount on a given sales item. The class has two instance variables: discount: an integer

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site