mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-17 04:51:58 -05:00
update:demo4
This commit is contained in:
22
com/study/demo4/TestTransport.java
Normal file
22
com/study/demo4/TestTransport.java
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user