1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rama09 [41]
3 years ago
7

Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount f

or the purchase of a given number of a single item. The method has two parameters, count and itemCost. 2. Derive a class BulkDiscount from DiscountPolicy, as described in the previous exercise. It should have a constructor that has two parameters, minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more than minimum, the discount is percent percent. 3. Derive a class BuyNItemsGetOneFree from DiscountPolicy, as described in Exercise 1. The class should have a constructor that has a single parameter n. In addition, the class should define the method computeDiscount so that every nth item is free. For example, the following table gives the discount for the purchase of various counts of an item that costs $10, when n is 3: count 1 2 3 4 5 6 7 Discount 0 0 10 10 10 20 20
4. Derive a class CombinedDiscount from DiscountPolicy, as described in Exercise 1. It should have a constructor that has two parameters of type DiscountPolicy. It should define the method computeDiscount to return the maximum value returned by computeDiscount for each of its two private discount policies. The two discount policies are described in Exercises 2 and 3. 5. Define DiscountPolicy as an interface instead of the abstract class described in Exercise 1.
Engineering
1 answer:
eimsori [14]3 years ago
6 0

Answer:

Java Code was used to define classes in the abstract discount policy,The bulk discount, The buy items get one free and the combined discount

Explanation:

Solution

Code:

Main.java

public class Main {

public static void main(String[] args) {

  BulkDiscount bd=new BulkDiscount(10,5);

BuyNItemsGetOneFree bnd=new BuyNItemsGetOneFree(5);

CombinedDiscount cd=new CombinedDiscount(bd,bnd);

System.out.println("Bulk Discount :"+bd.computeDiscount(20, 20));

  System.out.println("Nth item discount :"+bnd.computeDiscount(20, 20));

 System.out.println("Combined discount :"+cd.computeDiscount(20, 20));    

  }

}

discountPolicy.java

public abstract class DiscountPolicy

{    

public abstract double computeDiscount(int count, double itemCost);

}    

BulkDiscount.java  

public class BulkDiscount extends DiscountPolicy

{    

private double percent;

private double minimum;

public BulkDiscount(int minimum, double percent)

{

this.minimum = minimum;

this.percent = percent;

}

at Override

public double computeDiscount(int count, double itemCost)

{

if (count >= minimum)

{

return (percent/100)*(count*itemCost); //discount is total price * percentage discount

}

return 0;

}

}

BuyNItemsGetOneFree.java

public class BuyNItemsGetOneFree extends DiscountPolicy

{

private int itemNumberForFree;

public BuyNItemsGetOneFree(int n)

{

  itemNumberForFree = n;

}

at Override

public double computeDiscount(int count, double itemCost)

{

if(count > itemNumberForFree)

return (count/itemNumberForFree)*itemCost;

else

  return 0;

}

}

CombinedDiscount.java

public class CombinedDiscount extends DiscountPolicy

{

private DiscountPolicy first, second;

public CombinedDiscount(DiscountPolicy firstDiscount, DiscountPolicy secondDiscount)

{

first = firstDiscount;

second = secondDiscount;

}

at Override

public double computeDiscount(int count, double itemCost)

{

double firstDiscount=first.computeDiscount(count, itemCost);

double secondDiscount=second.computeDiscount(count, itemCost);

if(firstDiscount>secondDiscount){

  return firstDiscount;

}else{

  return secondDiscount;

}

}  

}

You might be interested in
What is the name of the first federation vessel in star trek hint 17?
Nitella [24]

Answer:

The Fesarius

Explanation:

It's the first vessel

7 0
2 years ago
Which statement about cathode ray tubes (CRTs) is true?
yuradex [85]

Answer:

CRTs consume less power than LCDs.

hope it helps (^^)

# Cary on learning

6 0
2 years ago
Suppose we use radix sort to sort the English-language strings below using standard lexicographic ordering (i.e. sort in alphabe
nlexa [21]

Answer:

a) 4 passes are required to sort the string.

b) 4

c)   i) TARP

    ii) CHIP

    iii) PART

    iv) TARP

    v) TARP

d) O(k+n), n is no. of strings, k is largest no. of character in among the string

   O(d*(n+10)), n is no. of integers

Explanation:

7 0
3 years ago
BE-40 What is a characteristic of a catamaran hull?
Nat2105 [25]

Answer:

<em>A stable ride</em>

Explanation:

A Catamaran hull is a form of sea craft invented by the Austronesian peoples, the invention of the Catamaran hull enabled these people to sail across the sea in their expansion to the islands of the Indian and Pacific Oceans. Catamaran has multiple hulls, usually two parallel hulls of equal size. This geometric feature gives the craft an increased stability because,<em> it derives extra stability from its wide beam, in the place of a ballasted keel employed in a regular monohull sailboat. </em>A Catamaran hull will require four times the force needed to capsize it, when compared to an equivalent monohull.

8 0
3 years ago
If you need to write a function that will compute the cost of some candy, where each piece costs 25 cents, which would be an app
masya89 [10]
The best answer would be

D. Int calculateCost(int count);
6 0
3 years ago
Other questions:
  • Will this airplane stay in the air a long time? Why or why not?
    9·1 answer
  • Engineers are designing a cylindrical air tank and are trying to determine the dimensions of the tank. The proposed material for
    14·1 answer
  • Write a matrix, that is a lower triangular matrix.
    15·1 answer
  • A chemistry student accidentally drops a large mercury thermometer and it breaks. The thermometer contained 2 grams of mercury (
    13·1 answer
  • As an employee, who is supposed to provide training on the chemicals you are handling or come in contact with at work?
    5·2 answers
  • What have you learned about designing solutions? How does this apply to engineering? Think of some engineering solutions that st
    15·1 answer
  • Only respond if your the person im talkin to
    14·1 answer
  • A single phase molor is located
    14·1 answer
  • A fine-grained soil has a liquid limit of 200%, determined from the Casagrande cup method. The plastic limit was measured by rol
    15·1 answer
  • Workplace bullying can cause_____hazards.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!