answer.
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]
2 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]2 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
Universal Containers has a junction object called "Job Production Facility". With 2 master-detail relationships to the Job and P
alexdok [17]

Answer:

C. The user will not be able to see the junction object records or the field values.

Explanation:

For the profile of the user to give access permission such as create and read to the job without granting access permission to the production facility object, the value of the field or records of the junction object will not be seen by the user. This is one of the necessary criteria or principle for the universal container with a junction object.

3 0
2 years ago
A cylindrical drum (2 ft. dia ,3 ft height) is filled with a fluid whose density is 40 lb/ft^3. Determine (a. the total volume o
Ksivusya [100]

Answer:

a)V=9.42\ ft^3

b)Mass in lb = 376.8 lb

Mass in slug = 11.71 slug

c)v=0.025\ ft^3/lb

d)w=1276 \ lb/ft.s^2

Explanation:

Given that

d= 2 ft

r= 1 ft

h= 3 ft

Density

\rho = 40\ lb/ft^3

a)

We know that volume V given as

V=\pi r^2 h

V=\pi \times 1^2\times 3

V=9.42\ ft^3

b)

Mass = Density x volume

mass =40\times 9.42\ lb

mass= 376.8 lb

We know that

1 lb = 0.031 slug

So 376.8 lb= 11.71 slug

Mass in lb = 376.8 lb

Mass in slug = 11.71 slug

c)

we know that specific volume(v) is the inverse of density.

v=\dfrac{1}{\rho}\ ft^3/lb

v=\dfrac{1}{40}\ ft^3/lb

v=0.025\ ft^3/lb

d)

Specific weight(w) is the product of density and the gravity(g).

w= ρ X g

w = 40 x 31.9

w=1276 \ lb/ft.s^2

8 0
2 years ago
When should you exercise extreme caution around power lines?
Elis [28]

<em>You should take note and exercise extreme precautions when you are near power lines and consider the following: </em>

<em> </em>

<em>1. Make sure that you have a good distance away from the lines. The minimum distance you can get is 10 feet away from the lines. Be cautious as well when you see broken lines as they could still harm you and electrified you. </em>

<em>2. Do not make ladders, equipments and things around you touch the power lines as it may harm you as well. </em>

<em>3. Clear everything and ensure that no things are near you before you lift your hands and other tools.</em>

6 0
2 years ago
A woodcutter wishes to cause the tree trunk to fall uphill, even though the trunk is leaning downhill. With the aid of the winch
Sedbober [7]

Answer:

The correct answer will be "400.4 N". The further explanation is given below.

Explanation:

The given values are:

Mass of truck,

m = 600 kg

g = 9.8 m/s²

On equating torques at the point O,

⇒  T\times Cos(10+5)\times (1.3+4)=mg\times Sin(5)\times 4

So that,

On putting the values, we get

⇒  T\times Cos(15^{\circ})\times 5.3=600\times 9.8\times Sin(5^{\circ})\times 4

⇒                             T=400.4 \ N

8 0
2 years ago
To find the reactance XLXLX_L of an inductor, imagine that a current I(t)=I0sin(ωt)I(t)=I0sin⁡(ωt) , is flowing through the indu
Sophie [7]

Answer:

V(t) = XLI₀sin(π/2 - ωt)

Explanation:

According to Maxwell's equation which is expressed as;

V(t) = dФ/dt ........(1)

Magnetic flux Ф can also be expressed as;

Ф = LI(t)

Where

L = inductance of the inductor

I = current in Ampere

We can therefore Express Maxwell equation as:

V(t) = dLI(t)/dt ....... (2)

Since the inductance is constant then voltage remains

V(t) = LdI(t)/dt

In an AC circuit, the current is time varying and it is given in the form of

I(t) = I₀sin(ωt)

Substitutes the current I(t) into equation (2)

Then the voltage across inductor will be expressed as

V(t) = Ld(I₀sin(ωt))/dt

V(t) = LI₀ωcos(ωt)

Where cos(ωt) = sin(π/2 - ωt)

Then

V(t) = ωLI₀sin(π/2 - ωt) .....(3)

Because the voltage and current are out of phase with the phase difference of π/2 or 90°

The inductive reactance XL = ωL

Substitute ωL for XL in equation (3)

Therefore, the voltage across inductor is can be expressed as;

V(t) = XLI₀sin(π/2 - ωt)

3 0
2 years ago
Other questions:
  • A_____ transducer is a device that can convert an electronic controller output signal into a standard pneumatic output. A. pneum
    13·1 answer
  • A woman approaches a room attendant with a letter. She requests that the attendant leave the letter in Room 1201. Which is the m
    9·1 answer
  • You work in Madison, Wisconsin. It is January and the area has been hit with bad weather. Another weather front is expected to a
    9·1 answer
  • Current density is given in cylindrical coordinates as J = −106z1.5az A/m2 in the region 0 ≤ rho ≤ 20 µm; for rho ≥ 20 µm, J = 0
    13·1 answer
  • 15. A cold-chamber die-casting machine operates automatically, supported by two industrial robots.The machine produces two zinc
    9·2 answers
  • Discuss your interpretation of the confidence-precision trade-off, and provide a few examples of how you might make a choice in
    14·1 answer
  • A 10-m long steel linkage is to be designed so that it can transmit 2 kN of force without stretching more than 5 mm nor having a
    9·1 answer
  • What ratio between differential gain and common-mode gain is called​
    9·1 answer
  • Milton has been tracking the migrating patterns of whales in the northwest Atlantic Ocean for five years. He knows where and whe
    5·2 answers
  • The BARO sensor informs the PCM about changes in weather and ____________________.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!