期末作业二

import java.util.Scanner;

// 客户类
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;
    }

    // Getter and Setter methods
    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 int orderId;
    private double totalPrice;
    private String orderStatus;

    // 这里简化处理,没有直接关联商品和价格计算逻辑,只示范结构
    public double calculateTotalPrice(int quantity, double unitPrice) {
        return totalPrice = quantity * unitPrice;
    }

	public double getTotalPrice() {
		// TODO Auto-generated method stub
		return 0;
	}

    // 其他getter和setter省略...
}

// 支付接口
interface Payment {
    void makePayment(double amount);
}

// 信用卡支付类
class CreditCardPayment implements Payment {
    @Override
    public void makePayment(double amount) {
        System.out.println("Processing payment of $" + amount + " via credit card.");
    }
}

// PayPal支付类
class PayPalPayment implements Payment {
    @Override
    public void makePayment(double amount) {
        System.out.println("Processing payment of $" + amount + " via PayPal.");
    }
}

// 支付简单工厂类
class PaymentFactory {
    public static Payment createPayment(String paymentMethod) {
        if ("credit_card".equalsIgnoreCase(paymentMethod)) {
            return new CreditCardPayment();
        } else if ("paypal".equalsIgnoreCase(paymentMethod)) {
            return new PayPalPayment();
        } else {
            throw new IllegalArgumentException("Invalid payment method.");
        }
    }
}

public class OnlineShoppingSystem18 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("客户名称:");
        String customerName = scanner.nextLine();
        String customerAddress = scanner.nextLine();
        String phoneNumber = scanner.nextLine();

        Customer customer = new Customer(customerName, customerAddress, phoneNumber);

        System.out.println("创建订单...");
        Order order = new Order();
        // 示例:假设的商品数量和单价,实际应用中应从UI或数据库获取
        order.calculateTotalPrice(2, 50); // 假设订购了2件商品,每件50元

        System.out.println("支付方式 [微信, 支付宝]:");
        String chosenPaymentMethod = scanner.nextLine().toLowerCase();

        Payment payment = PaymentFactory.createPayment(chosenPaymentMethod);
        payment.makePayment(order.getTotalPrice()); // 假定getTotalPrice已正确实现获取总价

        scanner.close();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值