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
In a CNC machining operation, the has to be moved from point (5, 4) to point(7, 2)along a circular path with center at (7,2). Be
notka56 [123]

Answer: hello your question is incomplete below is the complete question

answer:

N010 GO2 X7.0 Y2.0 15.0 J2.0  ( option 1 )

Explanation:

Given that the NC machining has to be moved from point ( 5,4 ) to point ( 7,2 ) along a circular path

GO2 = circular interpolation in a clockwise path

G91 = incremental dimension

<em>hence the correct option is </em>:

N010 GO2 X7.0 Y2.0 15.0 J2.0  

6 0
3 years ago
It is the same as force. b. Stress that is created by plate collision is the same everywhere and reflects the total force produc
Vlada [557]

Answer:

Explanation:

ωωωωωωωωω

7 0
2 years ago
Consider the expansion of a gas at a constant temperature in a water-cooled piston-cylinder system. The constant temperature is
Leona [35]

Answer:

Q_{in} = W_{out} = nRT ln (\frac{V_{2}}{V_{1}})

Explanation:

According to the first thermodynamic law, the energy must be conserved so:

dQ = dU - dW

Where Q is the heat transmitted to the system, U is the internal energy and W is the work done by the system.

This equation can be solved by integration between an initial and a final state:

(1) \int\limits^1_2 {} \, dQ = \int\limits^1_2 {} \, dU - \int\limits^1_2 {} \, dW

As per work definition:

dW = F*dr

For pressure the force F equials the pressure multiplied by the area of the piston, and considering dx as the displacement:

dW = PA*dx

Here A*dx equals the differential volume of the piston, and considering that any increment in volume is a work done by the system, the sign is negative, so:

dW = - P*dV

So the third integral in equation (1) is:

\int\limits^1_2 {- P} \, dV

Considering the gas as ideal, the pressure can be calculated as P = \frac{n*R*T}{V}, so:

\int\limits^1_2 {- P} \, dV = \int\limits^1_2 {- \frac{n*R*T}{V}} \, dV

In this particular case as the systems is closed and the temperature constant, n, R and T are constants:

\int\limits^1_2 {- \frac{n*R*T}{V}} \, dV = -nRT \int\limits^1_2 {\frac{1}{V}} \, dV

Replacion this and solving equation (1) between state 1 and 2:

\int\limits^1_2 {} \, dQ = \int\limits^1_2 {} \, dU + nRT \int\limits^1_2 {\frac{1}{V}} \, dV

Q_{2} - Q_{1} = U_{2} - U_{1} + nRT(ln V_{2} - ln V_{1})

Q_{2} - Q_{1} = U_{2} - U_{1} + nRT ln \frac{V_{2}}{V_{1}}

The internal energy depends only on the temperature of the gas, so there is no internal energy change U_{2} - U_{1} = 0, so the heat exchanged to the system equals the work done by the system:

Q_{in} = W_{out} = nRT ln (\frac{V_{2}}{V_{1}})

4 0
3 years ago
How does heat conduction differ from convection?
Helga [31]

Explanation:

Conduction:

     Heat transfer in the conduction occurs due to movement of molecule or we can say that due to movement of electrons in the two end of same the body. Generally,  phenomenon of conduction happens in the case of solid . In conduction heat transfer takes places due to direct contact of two bodies.

Convection:

              In convection heat transfer of fluid takes place due to density difference .In simple words we can say that heat transfer occur due to motion of fluid.

7 0
3 years ago
Read 2 more answers
CS3733: Homework/Practice 05 Suppose we would like to write a program called monitor which allows two other programs to communic
valina [46]

Answer:

#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<sys/types.h>

#include<string.h>

#include<pthread.h>

//#include<sys/wait.h>

int main(int argc, char** argv)

{

int fd1[2];

int fd2[2];

int fd3[2];

int fd4[2];

char message[] = "abcd";

char input_str[100];

pid_t p,q;

if (pipe(fd1)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd2)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd3)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd4)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

p = fork();

if (p < 0)

{

 fprintf(stderr, "fork Failed" );

return 1;

}

// child process-1

else if (p == 0)

{

 close(fd1[0]);// Close reading end of first pipe

 char concat_str[100];

 printf("\n\tEnter meaaage:"):

 scanf("%s",concat_str);

 write(fd1[1], concat_str, strlen(concat_str)+1);

 // Concatenate a fixed string with it

 int k = strlen(concat_str);

 int i;

 for (i=0; i<strlen(fixed_str); i++)

 {

  concat_str[k++] = fixed_str[i];

 }

 concat_str[k] = '\0';//string ends with '\0'

 // Close both writting ends

 close(fd1[1]);

 wait(NULL);

//.......................................................................

 close(fd2[1]);

 read(fd2[0], concat_str, 100);

 if(strcmp(concat_str,"invalid")==0)

 {

 printf("\n\tmessage not send");

 }

 else

 {

  printf("\n\tmessage send to prog_2(child_2).");

 }

 close(fd2[0]);//close reading end of pipe 2

 exit(0);

}

else

{

 close(fd1[1]);//Close writting end of first pipe

 char concat_str[100];

 read(fd1[0], concal_str, strlen(concat_str)+1);

 close(fd1[0]);

 close(fd2[0]);//Close writing end of second pipe

 if(/*check if msg is valid or not*/)

 {

  //if not then

  write(fd2[1], "invalid",sizeof(concat_str));

  return 0;

 }

 else

 {

  //if yes then

  write(fd2[1], "valid",sizeof(concat_str));

  close(fd2[1]);

  q=fork();//create chile process 2

  if(q>0)

  {

   close(fd3[0]);/*close read head offd3[] */

   write(fd3[1],concat_str,sizeof(concat_str);//write message by monitor(main process) using fd3[1]

   close(fd3[1]);

   wait(NULL);//wait till child_process_2 send ACK

   //...........................................................

   close(fd4[1]);

   read(fd4[0],concat_str,100);

   close(fd4[0]);

   if(sctcmp(concat_str,"ack")==0)

   {

    printf("Messageof child process_1 is received by child process_2");

   }

   else

   {

    printf("Messageof child process_1 is not received by child process_2");

   }

  }

  else

  {

   if(p<0)

   {

    printf("Chiile_Procrss_2 not cheated");

   }

   else

   {

     

    close(fd3[1]);//Close writing end of first pipe

    char concat_str[100];

    read(fd3[0], concal_str, strlen(concat_str)+1);

    close(fd3[0]);

    close(fd4[0]);//Close writing end of second pipe

    write(fd4[1], "ack",sizeof(concat_str));

     

   }

  }

 }

 close(fd2[1]);

}

}

8 0
3 years ago
Other questions:
  • A corroded metal gusset plate was found on a bridge. It was estimated that the original area of the plate was 750 cm2 and that a
    11·1 answer
  • Consider flow in between two parallel plates located a distance H from each other. Fluid flow is driven by the bottom plate movi
    15·1 answer
  • What is pessimism technology
    12·1 answer
  • Which statement about direct-mail messages is most accurate? Group of answer choices Direct mail is an effective channel for per
    15·1 answer
  • Water of dynamic viscosity 1.12E-3 N*s/m2 flows in a pipe of 30 mm diameter. Calculate the largest flowrate for which laminar fl
    13·1 answer
  • A city emergency management agency and a construction company have formed a public-private partnership. The construction company
    15·1 answer
  • Select three functions of catalysts.
    9·1 answer
  • You are hired as the investigators to identify the root cause and describe what should have occurred based on the following info
    9·1 answer
  • A 1.9-mm-diameter tube is inserted into an unknown liquid whose density is 960 kg/m3, and it is observed that the liquid rises 5
    7·1 answer
  • It is possible to design a reactor where the scy conductor and the nitrogen/ammonia electrode operate at different temperatures.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!