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
Which one of the following questions about population growth is the only TRUE statement?A) The size of a population can never ex
tatyana61 [14]

Answer:

Explanation:

5

6 0
3 years ago
NAME JUICE WRLDS SONG THAT HE BLEW UP ON
creativ13 [48]

Answer:

lucid dreams :)

Explanation:

5 0
3 years ago
Read 2 more answers
A gas expands in a piston-cylinder assembly from p1 = 8 bar, V1 = 0.02 m3 to p2 = 2 bar. The relation between pressure and volum
Charra [1.4K]

Answer:

The heat transfer is 29.75 kJ

Explanation:

The process is a polytropic expansion process

General polytropic expansion process is given by PV^n = constant

Comparing PV^n = constant with PV^1.2 = constant

n = 1.2

(V2/V1)^n = P1/P2

(V2/0.02)^1.2 = 8/2

V2/0.02 = 4^(1/1.2)

V2 = 0.02 × 3.2 = 0.064 m^3

W = (P2V2 - P1V1)/1-n

P1 = 8 bar = 8×100 = 800 kPa

P2 = 2 bar = 2×100 = 200 kPa

V1 = 0.02 m^3

V2 = 0.064 m^3

1 - n = 1 - 1.2 = -0.2

W = (200×0.064 - 800×0.02)/-0.2 = -3.2/-0.2 = 16 kJ

∆U = 55 kJ/kg × 0.25 kg = 13.75 kJ

Heat transfer (Q) = ∆U + W = 13.75 + 16 = 29.75 kJ

7 0
2 years ago
6. At a construction site, cement, sand, and gravel are used to make concrete. The ratio of cement to sand to gravel is 1 to 2.4
S_A_V [24]

Answer:

Mass of cement used is 62.5 lb

Mass of gravel used is 225 lb

Explanation:

The ratio given here is cement to sand to gravel = 1 : 2.4 : 3.6

So, for 150 lb of sand

C : S : G = 1 : 2.4 : 3.6

\frac{C}{S}=\frac{1}{2.4}\\\Rightarrow C=S\frac{1}{2.4}\\\Rightarrow C=150\frac{1}{2.4}\\\Rightarrow C=62.5\ lb

Mass of cement used is 62.5 lb

\frac{S}{G}=\frac{2.4}{3.6}\\\Rightarrow G=S\frac{3.6}{2.4}\\\Rightarrow C=150\frac{3.6}{2.4}\\\Rightarrow C=225\ lb

Mass of gravel used is 225 lb

7 0
3 years ago
Determine ten different beam loading values that will be used in lab to end load a cantilever beam using weights. Load values sh
nasty-shy [4]

Answer:

1st value = 1.828 * 10 ^9 gm/m^2 -------     10th value = 7.312 * 10^9 gm/m^2

Explanation:

initial load ( Wp) = 200 g

W1 ( value by which load values increase ) = 100 g

Ten different beam loading values :

Wp + w1 = 300g ----- p1

Wp + 2W1 = 400g ---- p2

Wp + 3W1 = 500g ----- p3 ----------------- Wp + 10W1 = 1200g ---- p10

x = 10.25" = 0.26 m

b = 1.0" = 0.0254 m

t = 0.125" = 3.175 * 10^-3 m

using the following value to determine the load values at different beam loading values

attached below is the remaining part fo the solution

5 0
3 years ago
Other questions:
  • A forklift raises a 90.5 kg crate 1.80 m. (a) Showing all your work and using unity conversion ratios, calculate the work done b
    14·2 answers
  • Number the statements listed below in the order that they would occur in engine operation. Then, label these stages as intake, c
    14·1 answer
  • Calculate the viscosity(dynamic) and kinematic viscosity of airwhen
    9·1 answer
  • How to design a solar panel<br>​
    7·1 answer
  • A 100-ampere resistor bank is connected to a controller with conductor insulation rated 75°C. The resistors are not used in conj
    8·1 answer
  • ASAP correct answer plss When you are driving, if you see this traffic sign it means
    8·1 answer
  • DUE AT 3:00!!!!!
    13·2 answers
  • What speeds did john j montgomerys gliders reach
    12·1 answer
  • A hammer can be used to see how a mineral breaks. If you observe square chunks of the mineral when broken, what can you conclude
    15·1 answer
  • Valorant Or Csgo? which is best in your opinion?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!