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
Can you solve this question​
Alecsey [184]

Answer:

eojcjksjsososisjsiisisiiaodbjspbcpjsphcpjajosjjs ahahhahahahahahahahahahahahahhhahahahaahahhahahahahaahahahahaha

6 0
3 years ago
Read 2 more answers
A long corridor has a single light bulb and two doors with light switch at each door.
Tpy6a [65]

Answer:

  Light = A xor B

Explanation:

If switches A and B produce True or False, then Light will be True for ...

  Light = A xor B

8 0
3 years ago
The seers were of the opinion that_____ . *
AURORKA [14]

Answer:

✔️a healthy mind resides in a healthy body.

Explanation:

The seers were of the opinion that "a healthy mind resides in a healthy body."

Just like the English translation of a famous quotation from Thales, pre-Socratic Greek philosopher puts it "a sound mind in a sound body"; which tries to demonstrate the close connections that exists in bodily well-being and one's ability to enjoy life.

The seers were actually of the opinion that a healthy mind resides in a healthy body. It implies that there is connection between the body and the mind. When the body catches an illness, the mind and other parts of the body are affected. When our minds are not healthy, it affects the effective functioning of the body.

So, a healthy mind will definitely be found in a healthy body.

4 0
3 years ago
2. A counter flow tube-shell heat exchanger is used to heat a cold water stream from 18 to 78oC at a flow rate of 1 kg/s. Heatin
Anastaziya [24]

Answer:

a) L = 220\,m, b) U_{o} \approx 0.63\,\frac{kW}{m^{2}\cdot ^{\textdegree}C}

Explanation:

a) The counterflow heat exchanger is presented in the attachment. Given that cold water is an uncompressible fluid, specific heat does not vary significantly with changes on temperature. Let assume that cold water has the following specific heat:

c_{p,c} = 4.186\,\frac{kJ}{kg\cdot ^{\textdegree}C}

The effectiveness of the counterflow heat exchanger as a function of the capacity ratio and NTU is:

\epsilon = \frac{1-e^{-NTU\cdot(1-c)}}{1-c\cdot e^{-NTU\cdot (1-c)}}

The capacity ratio is:

c = \frac{C_{min}}{C_{max}}

c = \frac{(1\,\frac{kg}{s} )\cdot(4.186\,\frac{kW}{kg^{\textdegree}C} )}{(1.8\,\frac{kg}{s} )\cdot(4.30\,\frac{kW}{kg^{\textdegree}C} )}

c = 0.541

Heat exchangers with NTU greater than 3 have enormous heat transfer surfaces and are not justified economically. Let consider that NTU = 2.5. The efectiveness of the heat exchanger is:

\epsilon = \frac{1-e^{-(2.5)\cdot(1-0.541)}}{1-(2.5)\cdot e^{-(2.5)\cdot (1-0.541)}}

\epsilon \approx 0.824

The real heat transfer rate is:

\dot Q = \epsilon \cdot \dot Q_{max}

\dot Q = \epsilon \cdot C_{min}\cdot (T_{h,in}-T_{c,in})

\dot Q = (0.824)\cdot (4.186\,\frac{kW}{^{\textdegree}C} )\cdot (160^{\textdegree}C-18^{\textdegree}C)

\dot Q = 489.795\,kW

The exit temperature of the hot fluid is:

\dot Q = \dot m_{h}\cdot c_{p,h}\cdot (T_{h,in}-T_{h,out})

T_{h,out} = T_{h,in} - \frac{\dot Q}{\dot m_{h}\cdot c_{p,h}}

T_{h,out} = 160^{\textdegree}C + \frac{489.795\,kW}{(7.74\,\frac{kW}{^{\textdegree}C} )}

T_{h,out} = 96.719^{\textdegree}C

The log mean temperature difference is determined herein:

\Delta T_{lm} = \frac{(T_{h,in}-T_{c, out})-(T_{h,out}-T_{c,in})}{\ln\frac{T_{h,in}-T_{c, out}}{T_{h,out}-T_{c,in}} }

\Delta T_{lm} = \frac{(160^{\textdegree}C-78^{\textdegree}C)-(96.719^{\textdegree}C-18^{\textdegree}C)}{\ln\frac{160^{\textdegree}C-78^{\textdegree}C}{96.719^{\textdegree}C-18^{\textdegree}C} }

\Delta T_{lm} \approx 80.348^{\textdegree}C

The heat transfer surface area is:

A_{i} = \frac{\dot Q}{U_{i}\cdot \Delta T_{lm}}

A_{i} = \frac{489.795\,kW}{(0.63\,\frac{kW}{m^{2}\cdot ^{\textdegree}C} )\cdot(80.348^{\textdegree}C) }

A_{i} = 9.676\,m^{2}

Length of a single pass counter flow heat exchanger is:

L =\frac{A_{i}}{\pi\cdot D_{i}}

L = \frac{9.676\,m^{2}}{\pi\cdot (0.014\,m)}

L = 220\,m

b) Given that tube wall is very thin, inner and outer heat transfer areas are similar and, consequently, the cold side heat transfer coefficient is approximately equal to the hot side heat transfer coefficient.

U_{o} \approx 0.63\,\frac{kW}{m^{2}\cdot ^{\textdegree}C}

5 0
3 years ago
Before you disconnect the service battery from the discharged battery, it is good practice to place a load across the
Lilit [14]

Answer:

it is true i just did this test

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • Refers to the capability to keep moving forward on a specified grade.
    5·1 answer
  • Which of the following describes fibers? a)- Single crystals with extremely large length-to-diameter ratios. b)- Polycrystalline
    10·1 answer
  • The fan blades suddenly experience an angular acceleration of 2 rad/s2. If the blades are rotating with an initial angular veloc
    10·1 answer
  • In digital communication technologies, what is an internal network also known as?
    9·1 answer
  • A ball thrown vertically upward from the top of a building of 60ft with an initial velocity of vA=35 ft/s. Determine (a) how hig
    8·1 answer
  • What is an air mass?​
    5·2 answers
  • Importance of civil engineering in nepal?​
    10·1 answer
  • Determine the number of flipflops required to build a binary counter that count from 0 to 2043
    14·1 answer
  • Random question, does anyone here use Lego, do not answer unless that is a yes
    15·2 answers
  • Plz help electrical technology
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!