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
Discuss the applications of numerical weather forecasting​
olchik [2.2K]

Numerical weather prediction (NWP) uses mathematical models of the atmosphere and oceans to predict the weather based on current weather conditions. Though first attempted in the 1920s, it was not until the advent of computer simulation in the 1950s that numerical weather predictions produced realistic results. A number of global and regional forecast models are run in different countries worldwide, using current weather observations relayed from radiosondes, weather satellites and other observing systems as inputs.
3 0
3 years ago
Which bulb has the lowest total cost of operation? (a) Incandescent (b) Fluorescent (c) LED
Finger [1]

Answer: LED have the lowest cost of operation.

Explanation:

If we ignore the initial procurement cost of the items the operational cost of any device consuming electricity is given by

Cost=Energy\times cost/unit

Among the three item's LED consumes the lowest power to give the same level of brightness as compared to the other 2 item's thus LED's shall have the lowest operational cost.

6 0
3 years ago
Discuss in detail the following methods used to redistribute income and wealth in cash grants?​
aev [14]

Answer:

Redistribution of income and wealth is the transfer of income and wealth (including physical property) from some individuals to others through a social mechanism such as taxation, welfare, public services, land reform, monetary policies, confiscation, divorce or tort law.

-The term typically refers to redistribution on an economy-wide basis rather than between selected individuals.

Interpretations of the phrase vary, depending on personal perspectives, political ideologies and the selective use of statistics.

-It is frequently heard in politics, usually referring to perceived redistribution from those who have more to those who have less. Occasionally, however, it is used to describe laws or policies that cause opposite redistribution that shift monetary burdens from low-income earners to the wealthy.

-

The phrase is often coupled with the term class warfare, with high-income earners and the wealthy portrayed as victims of unfairness and discrimination.

-

Redistribution tax policy should not be confused with predistribution policies. "Predistribution" is the idea that the state should try to prevent inequalities from occurring in the first place rather than through the tax and benefits system once they have occurred. For example, a government predistribution policy might require employers to pay all employees a living wage, not just a minimum wage, as a "bottom-up" response to widespread income inequalities or high poverty rates.

Many alternate taxation proposals have been floated without the political will to alter the status quo. One example is the proposed "Buffett Rule", which is a hybrid taxation model composed of opposing systems, intended to minimize the favoritism of the special interest tax design.

7 0
2 years ago
Why Elastic Modulus is important and on what it depends?
Bad White [126]

Answer:

The Young's Modulus of a material is a fundamental property of every material that cannot be changed. It is dependent upon temperature and pressure however. The Young's Modulus (or Elastic Modulus) is in essence the stiffness of a material. In other words, it is how easily it is bended or stretched.

Explanation:

Have a great day

5 0
3 years ago
What are the three most common types of relearn procedures?
WITCHER [35]

Answer:

The three types of relearn procedures are auto relearn, stationary and OBD.

Explanation:

In TPMS system, after the direct service like adjustment of air pressure, tire rotation or replacement of sensors etc, is performed then maximum vehicle  often needs TPMS system relearn that needs to be performed.

For performing these relearn procedure, there are mainly three types:

  1. auto relearn
  2. stationary relearn
  3. OBD

After applying the relearn process, the TPMS system will again be in proper function.

8 0
3 years ago
Other questions:
  • Which option is a potential environmental risk of adopting a new technology?
    5·1 answer
  • // This program accepts data about 100 books and// determines a price for each.// The price is 10 cents per page for the// first
    12·1 answer
  • If a signal is transmitted at a power of 250 mWatts (mW) and the noise in the channel is 10 uWatts (uW), if the signal BW is 20M
    13·1 answer
  • Ayuda con este problema de empuje y principio de arquimedes.
    6·1 answer
  • For the system in problem 4, suppose a main memory access requires 30ns, the page fault rate is .01%, it costs 12ms to access a
    14·1 answer
  • 1) Each of the following would be considered company-confidential except
    10·1 answer
  • Resistors of 150 Ω and 100 Ω are connected in parallel. What is their equivalent resistance?
    13·1 answer
  • Which process made making copies of technical drawings easier?
    8·1 answer
  • Select the correct answer.
    11·1 answer
  • Please help me on this it’s due now
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!