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
How does a turbo charger work
Romashka-Z-Leto [24]

Answer:

The turbocharger on a car applies a very similar principle to a piston engine. It uses the exhaust gas to drive a turbine. This spins an air compressor that pushes extra air (and oxygen) into the cylinders, allowing them to burn more fuel each second

Explanation:

7 0
3 years ago
Read 2 more answers
Why are Gas cars Bad?(cons) pls help me its part of project thx<br>:) thx if u do help​
o-na [289]

Answer:

  • Depletes Fossil Fuels
  • Polution

Explanation:

Fossil Fuels take millions of years to be made. Gasoline is made up of primarily petroleum (a fossil fuel) which is easily refined into gasoline or kerosene. This means that once you run out of a fossil fuel...you're out of it.

Gas cars are also very big polutants. If you've ever heard of an emmisions test for a car, it is a test that sees how much pollution a car puts out into the air. It meassures how safe those levels are. This is a big indicator of how much cars pollute becasue there is a need to test your car every year. The gases that can be put into the air are harmful not only to humans and animals but to the climate and atmosphere.

5 0
3 years ago
A plane surface 25 cm wide has its temperature maintained at 80°C. Atmospheric air at 25°C ows parallel to the surface
Gre4nikov [31]

Answer:

See the detailed answer in attached file.

Explanation :

Download docx
3 0
3 years ago
Compare and contrast ""centralized"" and ""decentralized"" routing algorithms. (What are the advantages and disadvantages of eac
pantera1 [17]

Answer:

Comparison between centralized and decentralized routing algorithms:

The major similarity between both centralized and decentralized routing algorithms is that they are both communication serving systems. They both utilize node system(e.g, computer) and are both a communication liking system( e.g, Cable).

Contrasting between centralized and decentralized routing algorithms:

There are few differences between these two type of communication link or path way system but to name a couple of them,

For centralized, there is a single client server distribution node which simply means that one or more client server system are connected to a central processing server.

This also means that if the central processing server or pathway fails, it leads to the failure of the entire system. That is, there is no sending, responding or general processing of any form of requests. Example of a system that uses the centralized routing algorithm is the google search engine.

WHILE:

for the decentralized routing algorithms, there are multiple client server distribution pathway and each server makes its own decision. Here,there is no single entity that receives and responds to the request therefore,failure of any form of central path way processing node does not lead to the failure of the whole system unlike for the centralized system.

Advantages of centralized routing algorithm:

It can be easily protected or secured due to the nature of the system. If the central node is been secured, it generally translate to the different client node being secured.

It is easy to disconnect a connected client node from the central pathway node or central server as the case may be.

Disadvantages of centralized routing algorithm:

The client nodes are totally dependent on the central node or server so if there is a failure in the central server, the client node is then totally shut down.

Advantages of decentralized routing algorithm:

There is a random distribution of data on all the processing node or server which automatically creates a form of balance within the system. This leads to minimal or no down time processing client request.

Disadvantages of decentralized routing algorithm:

Due to the nature or fact that there are multiple processing system for different client node, it is difficult to detect which client node or request processing server is faulty. This can lead to delay in the fixing of fault in the system should it arise.

Why do we prefer a ""decentralized"" algorithm for routing messages through the internet?

The major reason why decentralized algorithm routing is preferred is because of the level of security attached to it. Each processing servers are secured independently and there is privilege of utilizing independent networking system.

5 0
3 years ago
Did you know whales have hip leg and shin bones? well now you do
storchak [24]

Answer:

No, I did not. Thank you for educating me!

Explanation:

Have a great day!

6 0
2 years ago
Other questions:
  • 4.71 A full-wave rectifier circuit with a 1-kΩ operates from a 120-V (rms) 60-Hz household supply through a 6-to-1 transformer h
    10·1 answer
  • Ammonia gas is diffusing at a constant rate through a layer of stagnant air 1 mm thick. Conditions are such that the gas contain
    14·1 answer
  • What type of companies would employ in mechanics engineering​
    8·1 answer
  • Why is low voltage advantageous in arc welding?
    5·1 answer
  • Which of the following manufacturing tools machines parts by moving the part into the cutting tool (instead of moving the cuttin
    13·1 answer
  • A reservoir delivers water to a horizontal pipeline 39 long The first 15 m has a diameter of 50 mm, after which it suddenly beco
    8·1 answer
  • What is meant by the thickness to chord ratio of an aerofoil?
    12·1 answer
  • Technician A says it will save you money if you get a high interest rate from a bank on the loan. Technician B says it is always
    10·1 answer
  • What are the functions of each computer program
    7·1 answer
  • Why is personal development necessary based activity success life and career​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!