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
A 1.00 liter solution contains 0.46 M hydrocyanic acid and 0.35 M potassium cyanide If 25.0 mL of water are added to this system
victus00 [196]
I won leader solution contain 0.46 mL of hydronic I said of 0.3 potassium
4 0
2 years ago
Grinding with the portable disc grinder should not be done in an area which​
emmainna [20.7K]
Nothing flammable of explosive type of material is around
7 0
2 years ago
Water flows in a tube that has a diameter of D= 0.1 m. Determine the Reynolds number if the average velocity is 10 diameters per
Cloud [144]

Answer:

a) Re_{D} = 111896.745, b) Re_{D} = 1.119\times 10^{-7}

Explanation:

a) The Reynolds number for the water flowing in a circular tube is:

Re_{D} = \frac{\rho\cdot v\cdot D}{\mu}

Let assume that density and dynamic viscosity at 25 °C are 997\,\frac{kg}{m^{3}} 0.891\times 10^{-3}\,\frac{kg}{m\cdot s}, respectively. Then:

Re_{D}=\frac{(997\,\frac{kg}{m^{3}} )\cdot (1\,\frac{m}{s} )\cdot (0.1\,m)}{0.891\times 10^{-3}\,\frac{kg}{m\cdot s} }

Re_{D} = 111896.745

b) The result is:

Re_{D}=\frac{(997\,\frac{kg}{m^{3}} )\cdot (10^{-6}\,\frac{m}{s} )\cdot (10^{-7}\,m)}{0.891\times 10^{-3}\,\frac{kg}{m\cdot s} }

Re_{D} = 1.119\times 10^{-7}

6 0
3 years ago
Determine the static pressure to stagnation pressure ratio associated with the following motion in standard air: (a) a runner mo
vredina [299]

Answer: a) 0.00017

b) 0.0013

c) 0.0022

d) 0.017

Explanation:

3 0
3 years ago
How can I solve this sequence problem?​
Vinvika [58]

Answer:

Podes  hablar en español?

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • A 100 kmol/h stream that is 97 mole% carbon tetrachloride (CCL) and 3% carbon disulfide (CS2) is to be recovered from the bottom
    7·1 answer
  • Estimate the daily carbon utilization to remove chlorobenzene from 1.0 MGD of ground water saturated with chlorobenzene. Assume
    12·1 answer
  • A horizontal channel of height H has two fluids of different viscosities and densities flowing because of a pressure gradient dp
    5·1 answer
  • What is the key to being a good engineer?
    15·2 answers
  • The depletion in the Ozone layer is caused by:
    14·2 answers
  • Steven is starting a project that requires a specialized, experienced contractor. Which selection process is the most suitable f
    11·1 answer
  • Just need someone to talk to pls dont just use me for points
    5·1 answer
  • Rosita is planning an investigation to determine how a lifeboat's shape affects its
    8·1 answer
  • Meaning of <br> Evaporation
    12·2 answers
  • When starting up a dual fuel system, the temperature rise method for determining airflow cannot be used with the compressor cycl
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!