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]
4 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]4 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
If a 9V battery produces a current of 3 A through a load, what is the resistance of the load
Elden [556K]

3 ohms hope this helps :D ❤

7 0
3 years ago
Read 2 more answers
Situation: Peter is designing a new hybrid car that functions on solar power. He is currently working on sketches of his design
givi [52]

Answer:

whats the question?

Explanation:

8 0
2 years ago
For some transformation having kinetics that obey the Avrami equation (Equation 10.17), the parameter n is known to have a value
OleMash [197]

Answer:

t = 25.10 sec

Explanation:

we know that Avrami equation

Y = 1 - e^{-kt^n}

here Y is percentage of completion  of reaction = 50%

t  is duration of reaction = 146 sec

so,

0.50 = 1 - e^{-k^146^2.1}

0.50 = e^{-k306.6}

taking natural log on both side

ln(0.5) = -k(306.6)

k = 2.26\times 10^{-3}

for 86 % completion

0.86 = 1 - e^{-2.26\times 10^{-3} \times t^{2.1}}

e^{-2.26\times 10^{-3} \times t^{2.1}} = 0.14

-2.26\times 10^{-3} \times t^{2.1} = ln(0.14)

t^{2.1} = 869.96

t = 25.10 sec

5 0
3 years ago
How high a building could fire hoses effectively spray from the ground? Fire hose pressures are around 1 MPa. (It is also said t
Mrac [35]

Answer:

z_{2} = 91.640\,m

Explanation:

The phenomenon can be modelled after the Bernoulli's Principle, in which the sum of heads related to pressure and kinetic energy on ground level is equal to the head related to gravity.

\frac{P_{1}}{\rho\cdot g} + \frac{v_{1}^{2}}{2\cdot g}= z_{2}+\frac{P_{2}}{\rho\cdot g}

The velocity of water delivered by the fire hose is:

v_{1} = \frac{(300\,\frac{gal}{min} )\cdot(\frac{3.785\times 10^{-3}\,m^{3}}{1\,gal} )\cdot(\frac{1\,min}{60\,s} )}{\frac{\pi}{4}\cdot (0.3\,m)^{2}}

v_{1} = 0.267\,\frac{m}{s}

The maximum height is cleared in the Bernoulli's equation:

z_{2}= \frac{P_{1}-P_{2}}{\rho\cdot g} + \frac{v_{1}^{2}}{2\cdot g}

z_{2}= \frac{1\times 10^{6}\,Pa-101.325\times 10^{3}\,Pa}{(1000\,\frac{kg}{m^{3}} )\cdot(9.807\,\frac{m}{s^{2}} )} + \frac{(0.267\,\frac{m}{s} )^{2}}{2\cdot (9.807\,\frac{m}{s^{2}} )}

z_{2} = 91.640\,m

7 0
3 years ago
Ang ______ ay pagiging totoo o matuwid at hindi mahilig magsinungaling
IceJOKER [234]

Answer:

\purple{\rule{26pt}{5555555pt}}

6 0
3 years ago
Other questions:
  • Where the velocity is highest in the radial direction? Why?
    9·1 answer
  • Give a reason why fighter aircraft use mid-wing design.
    11·1 answer
  • An AX ceramic compound has the rock salt crystal structure. If the radii of the A and X ions are 0.137 and 0.241 nm, respectivel
    10·1 answer
  • A plane wall, 7.5 cm thick, generates heat internally at the rate of 105W/m3. One side of the wall is insulated and the other si
    14·1 answer
  • A local surf report provides the height of the wave from the trough to the crest of the wave. How does this relate to the wave’s
    11·1 answer
  • How many trains have been invented all around the world?
    14·1 answer
  • A Wii remote flung from a hand through a TV, with a kinetic energy of 1.44J and a mass of 4.5kg. Whats the velocity?
    6·1 answer
  • Why the power factor is Low in no load test in induction motor ?​
    13·1 answer
  • How does energy transition from one form to another as water moves from behind a dam to downstream of a dam?.
    8·1 answer
  • Imagine the arc of a football as it flies through the air. How does this motion illustrate classical mechanics?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!