update:demo4

This commit is contained in:
dichgrem
2025-11-28 16:59:17 +08:00
parent 41e6b71bd7
commit 5832b4fe9d
34 changed files with 307 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package com.study.demo4;
public class TestTransport {
public static void main(String[] args) {
// 测试自行车配送
DeliveryFeeCalculator bike = new BikeDeliveryCalculator();
System.out.println("自行车配送 3km: ¥" + bike.calculateFee(3));
System.out.println("自行车配送 8km: ¥" + bike.calculateFee(8));
// 测试汽车配送
DeliveryFeeCalculator car = new CarDeliveryCalculator();
System.out.println("汽车配送 3km: ¥" + car.calculateFee(3));
System.out.println("汽车配送 8km: ¥" + car.calculateFee(8));
// 对比不同距离的费用
System.out.println("\n费用对比:");
for (int km = 1; km <= 10; km++) {
System.out.printf("%dkm: 自行车¥%.1f, 汽车¥%.1f%n",
km, bike.calculateFee(km), car.calculateFee(km));
}
}
}