【无标题】

package w1;
public class Example2 {

    
    class Customer {
        private String name;
        private String address;
        private String phoneNumber;

        public Customer(String name, String address, String phoneNumber) {
            this.name = name;
            this.address = address;
            this.phoneNumber = phoneNumber;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getPhoneNumber() {
            return phoneNumber;
        }

        public void setPhoneNumber(String phoneNumber) {
            this.phoneNumber = phoneNumber;
        }
    }

 
    class Order {
        private String orderNumber;
        private double orderAmount;
        private String orderStatus;

        public Order(String orderNumber, double orderAmount) {
            this.orderNumber = orderNumber;
            this.orderAmount = orderAmount;
        }

        public double calculateTotalPrice(double quantity, double unitPrice) {
            return quantity * unitPrice;
        }
    }

   
    interface Payment {
        void makePayment(double amount);
    }

   
    class CreditCardPayment implements Payment {
      
        public void makePayment(double amount) {
            System.out.println("用信用卡付款了 " + amount + " 人民币");
        }
    }

  
    class PayPalPayment implements Payment {
    
        public void makePayment(double amount) {
            System.out.println("使用 PayPal付款了 " + amount + " 人民币");
        }
    }


    class PaymentFactory {
        public Payment createPayment(String paymentType) {
            if ("credit card".equals(paymentType)) {
                return new CreditCardPayment();
            } else if ("paypal".equals(paymentType)) {
                return new PayPalPayment();
            } else {
                throw new IllegalArgumentException("无效的支付类型");
            }
        }
    }

    public static void main(String[] args) {
        Example2 oss = new Example2();

       
        Customer customer = oss.new Customer("林志峰", "地址 1", "123456789");

        
        Order order = oss.new Order("17", 100.0);

    
        PaymentFactory paymentFactory = oss.new PaymentFactory();
        Payment payment = paymentFactory.createPayment("credit card");

      
        payment.makePayment(order.calculateTotalPrice(10,95740));
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值