import java.util.Scanner;
public class sdfdsfsddfs {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
int hours = 0; //停車時數
hours = 2;
park(hours);
System.out.println("--------------------");
hours = 3;
park(hours);
System.out.println("--------------------");
hours = 5;
park(hours);
System.out.println("--------------------");
hours = 8;
park(hours);
}
public static void park(int hours) {
int[] hourTable = {0, 2, 4, 6}; // 時段
int[] feeTable = {30, 50, 80, 100}; // 時段費率
int fee = 0; //停車費用
for(int i=3;i>=0;i--)
{
if(hours>hourTable[i])
{
fee+=(hours-hourTable[i])*feeTable[i];
hours=hourTable[i];
}
}
System.out.println("應繳費用:" + fee + "元整");
}
} |