Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for 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.

Answers

Answer 1

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;

}

}  

}


Related Questions

A complex gear drawing done on a drawing sheet marked M-1 has many section views showing important interior details of the gear. One of the cutting-plane lines is marked at the ends with a callout in a circular bubble that says 7 above a line and M-3 below the line. To find this detail, you would

Answers

Answer:

The answer is "go to sheet M-3 and look for a detail labeled 7".

Explanation:

In the given question some information is missing, that is choices so, the correct choice can be described as follows:

In gear drawing, we use equipment that sorts a very important technical reference necessary for machinery design.  If a manufacturer wants a tool in the production of a new computer, two choices are available to design the new equipment itself.  To use standard features that have already been developed. In this gear drawing to find the details we go to sheet in M-3 and for the detailed labeled 7.

A refrigerator uses refrigerant-134a as the working fluid and operates on the ideal vapor-compression refrigeration cycle except for the compression process. The refrigerant enters the evaporator at 120 kPa with a quality of 34 percent and leaves the compressor at 70°C. If the compressor consumes 450 W of power, determine (a) the mass flow rate of the refrigerant, (b) the condenser pressure, and (c) the COP of the refrigerator

Answers

Answer:

(a) 0.0064 kg/s

(b) 800 KPa

(c) 2.03

Explanation:

The ideal vapor compression cycle consists of following processes:

Process  1-2 Isentropic compression in a compressor

Process 2-3 Constant-pressure heat rejection in a condenser

Process 3-4 Throttling in an expansion device

Process 4-1 Constant-pressure heat absorption in an evaporator

For state 4 (while entering compressor):

x₄ = 34% = 0.34

P₄ = 120 KPa

from saturated table:

h₄ = hf + x hfg = 22.4 KJ/kg + (0.34)(214.52 KJ/kg)

h₄ = 95.34 KJ/kg

For State 1 (Entering Compressor):

h₁ = hg at 120 KPa

h₁ = 236.99 KJ/kg

s₁ = sg at 120 KPa = 0.94789 KJ/kg.k

For State 3 (Entering Expansion Valve)

Since 3 - 4 is an isenthalpic process.

Therefore,

h₃ = h₄ = 95.34 KJ/kg

Since this state lies at liquid side of saturation line, therefore, h₃ must be hf. Hence from saturation table we find the pressure by interpolation.

P₃ = 800 KPa

For State 2 (Leaving Compressor)

Since, process 2-3 is at constant pressure. Therefore,

P₂ = P₃ = 800 KPa

T₂ = 70°C (given)

Saturation temperature at 800 KPa is 31.31°C, which is less than T₂. Thus, this is super heated state. From super heated property table:

h₂ = 306.9 KJ/kg

(a)

Compressor Power = m(h₂ - h₁)

where,

m = mass flow rate of refrigerant.

m = Compressor Power/(h₂ - h₁)

m = (0.450 KJ/s)/(306.9 KJ/kg - 236.99 KJ/kg)

m = 0.0064 kg/s

(b)

Condenser Pressure = P₂ = P₃ = 800 KPa

(c)

The COP of ideal vapor compression cycle is given as:

COP = (h₁ - h₄)/(h₂ - h₁)

COP = (236.99 - 95.34)/(306.9 - 236.99)

COP = 2.03

The Ph diagram is attached

Other Questions
Argue who is to blame for Lennie's actions: Lennie for his inability to control himself or learn from his mistakes, or George, for failing to teach Lennie the importance of consequences? (Remember to answer in RACECE format for full credit.) * Which visual aid would most help a speech about the history of air travel?A. A diagram that shows the interior of a 747 jetB. A remote-controlled plane held by the speakerC. A cartoon of a flight attendant from the 1960sD. A graph showing the increase in jet speeds over time What are the negative consequences of underage teens using heroin? The Coercive Acts:A. shut down the Massachusetts legislature.B. prevented colonists from suing royal officials.C. closed Boston Harbor.D. all of the above Traci tries to teach her younger sister how to draw a rectangle. Traci tells her." Draw a shape with four straight sides." Traci sister draws the shape shown. The drawing of the shape includes 4 straight sides, but it is not a rectangle. How can Traci make her directions more clear? 1. What ideas came from the Magna Carta?2. What ideas came from Thomas Paines Common Sense?3. What are the purposes of government? Hint: look at the Preamble.4. The 1st three articles of the Constitution describe the three branches of government and their powers. What are the three branches of government? What does eachdo? Who is in each? What is a drug?What is the difference between medicines and recreational drugs ?Give two examples of legal recreational drugs?Give two example of illegal (against the law) drugs?What is a depressant?Give two effects that a depressant drug has on the body.Give two long term effect of taking a depressant drug.What is a stimulant?Give one example of a legal stimulant and one example of an illegal stimulant.What are the effects of taking a stimulant? What is the area of a rhombus if one diagonal is 6 centimeters and the other diagonal is 8 centimeters? who is john chivington A spinner with 4 colors is spun for a total of 50 trials. Yellow was selected 10 times. What is the experimental probability of the spinner landing on yellow? A. 2/25B. 1/5C. 1/4D. 2/5 Help.. 14 _____ are substances that can cause cancer.15 Scientists join cancer cells with antibody-producing white blood cells to produce _____. Which country is most likely to have large oil and natural gas reserves? Why? 6 things you should consider when planning a PowerPoint Presentation. Why is soap mixed with water?O A. The soap turns the water molecules into a nonpolar solvent.B. It covalently bonds to the water so it can be washed away.O C. Its polar end mixes with the water so it can be washed away.D. The soap becomes chemically active when mixed with water. Livia eats a chicken drumstick with 11 grams of protein. She also eats x cheese sticks, each with 7 grams of protein. The table shows y , the total number of grams of protein that Livia will consume if she eats x cheese sticks. Livia may eat only part of a cheese stick, so x may not always be a whole number. The images show two different fronts. Item A: A cold front and warm front meet with high level, grey clouds. Item B: Warm air is above cold and very cold air, lower clouds with rain falling. Which fronts are shown? arrange the events that led to the creation of israel in chronological order. the british mandate, the end of world war 2 and holocaust, the creation of the independent state of israel, britains restriction on jewish immigration, and the balfour declaration. Which of the following is a conversion from light energy to chemical energy?a. turning on a stove to heat dinnerb. growing an apple treec. turning on a lampd. Turning on a blender HURRY PLEASE!! WILL MARK THE BRAINLIEST Which of the following are factors of thepolynomial? evaluate the following function is f(x)=3x-2 and g(x)=5x+1 what is -2f(4)+3g(1)