0% found this document useful (0 votes)
27 views3 pages

04 Task Performance 1 - ARG1

N/A

Uploaded by

Luis Valencia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

04 Task Performance 1 - ARG1

N/A

Uploaded by

Luis Valencia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Luis Adrian S.

Valencia

Section: BT501

CODE

public interface Payment {

void pay(double amount); // Method signature without body

public class Online implements Payment {

private String email;

private String password;

public Online(String email, String password) {

this.email = email; // Assigning email to the class variable

this.password = password; // Assigning password to the class variable

@Override

public void pay(double amount) {

System.out.println("Paid using online account: " + amount);

public class Mobile implements Payment {

private String number;

private int pin;

public Mobile(String number, int pin) {

this.number = number; // Assigning number to the class variable

this.pin = pin; // Assigning pin to the class variable


}

@Override

public void pay(double amount) {

System.out.println("Paid using mobile wallet: " + amount);

public class Cart {

private double amount;

public Cart(double amount) {

this.amount = amount; // Assigning amount to the class variable

public void pay(Payment mode) {

mode.pay(amount); // Calling the pay method of the provided Payment


mode

public class TestStrategy {

public static void main(String[] args) {

Cart cart = new Cart(1512.75);

cart.pay(new Online("[email protected]", "Wasd8456!")); //


Online payment

cart = new Cart(375.25);

cart.pay(new Mobile("1234567890", 1234)); // Mobile payment


}

OUTPUT

You might also like