Professional Documents
Culture Documents
04 Task Performance 1
04 Task Performance 1
of them into a separate class, and make their objects interchangeable. Use NetBeans
to create a Java program that implements this design pattern. Name your project
TestStrategy.
this.password = password;
Use the pay method from the interface. Copy the code below.
public void pay (double amount) {
Add another class named Mobile that also implements the same interface. Declare two
private variables named number (String) and pin (int).
Add two (2) parameters to the constructor of this class. Follow the names and types
of your variables in the previous step.
Insert two (2) this statements into your constructor. Refer to the sample in Step
5.
Use the pay method again but edit the display message. Refer to the sample in Step
6.
Add a class named Cart. Declare a private double variable named amount.
Add a double parameter to its constructor. Then, write a this statement similar to
the sample in Step 6.
Add a pay method. Copy the code below for its content.
public void pay(Payment mode) {
mode.pay(amount);
Use the public class named TestStrategy to execute your Strategy pattern
implementation. In its main method, instantiate a Cart object named cart. Copy the
code below.
Cart cart = new Cart(1512.75);
Add a statement that uses the mobile payment mode. Refer to the second statement in
the sample above.
Sample Output: