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
50. You are not permitted to work on any equipment or machinery at any time if the
dexar [7]
I assume this is a wood shop question:

You may not work on any equipment if the TEACHER is not present in the room.
7 0
4 years ago
3 MAOP stands for which of the following?
raketka [301]

Answer:

MAOP Master of Arts in Organizational Psychology (various universities)

MAOP Maximum Allowable Operating Pressure

MAOP Mid-Atlantic Association of Oracle Professionals

MAOP Mid Atlantic Oncology Program

MAOP Maryland Association of Osteopathic Physicians

MAOP Master Air Operations Planner

MAOP Meharry Association of Office Personnel

MAOP Managers' Annual Operating Plan

MAOP Military Assistance Officer Program (US DoD)

Explanation:

3 0
3 years ago
1. One of these is NOT a type of pneumatic tool. Which one?
Serggg [28]

Answer:Circular

Explanation:

It’s the only thing not list under pneumatic tools‍♂️

5 0
3 years ago
Propane gas C3H8 enters a combustion chamber operating at steady state condition at 1 bar, 25ºC and is burned with 150% theoreti
GalinKa [24]

Answer:

see explaination

Explanation:

Balanced equation or stoichiometry equation means in a product after reaction there is no unburned carbon compound left or we can say the oxygen is sufficient to combine with all the carbon and hydrogen moleculs to form Carbon-dioxide and water respectively.

The dew point temperature of balanced equation will be 100°c because water vapour bis present in it and it will condense at 100°c at 1 bar pressure while the other products need much lower temperatures to liquify.

See attachment.

6 0
4 years ago
Read 2 more answers
Choose the true statement from those shown below: A Merchant Account allows you to use SSL on your web site. Disadvantages of us
Slav-nsk [51]

Answer:

The answer is A. that is, a merchant account allows you to use SSL on your website.

Explanation:

SSL means Secure Sockets Layer and this is an encryption-based Internet security protocol.

For an e-commerce merchant website or account, it is advised that an SSL package be installed to prevent any potential loss of private information.

For this reason, a merchant account allows use of SSL on your website because this also boost the confidence of client and customers visiting the website to purchase products.

7 0
3 years ago
Other questions:
  • A current powered by a battery is called what?
    5·1 answer
  • A series circuit in appliance consist of
    5·1 answer
  • What does it mean when the service engine light is on?
    13·1 answer
  • While he did not invent the assembly line, he did streamline his production line and was
    8·1 answer
  • For a very rough pipe wall the friction factor is constant at high Reynolds numbers. For a length L1 the pressure drop over the
    9·1 answer
  • Which one is an example of a digital input?
    5·1 answer
  • Why should females not be concerned about developing manly muscles? <br><br> Please help
    7·1 answer
  • Overconfidence in more male drivers, particularly those under 25 years old, results in them being involved in crashes.
    14·1 answer
  • Six 15-HP continuous-duty motors are connected to a common 480-volt feeder. The nameplate of each motor indicates: Full load amp
    10·1 answer
  • When a process is in a state of statistical control, all of the points on a control chart should fall within the control limits.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!