返回列表 發帖
  1. package text;
  2. public class JPA05 {
  3.     public static void main(String[] argv) {
  4.         int hours = 0;   //停車時數

  5.         hours = 2;
  6.         park(hours);
  7.         System.out.println("--------------------");
  8.         
  9.         hours = 3;
  10.         park(hours);
  11.         System.out.println("--------------------");
  12.         
  13.         hours = 5;
  14.         park(hours);
  15.         System.out.println("--------------------");
  16.         
  17.         hours = 8;
  18.         park(hours);
  19.     }
  20.    
  21.     public static void park(int hours) {
  22.         int[] hourTable = {0, 2, 4, 6};   // 時段
  23.         int[] feeTable = {30, 50, 80, 100};   // 時段費率
  24.         int fee = 0;   //停車費用
  25.         
  26.        for(int i=3;i>=0;i--)
  27.        {
  28.               if(hours>hourTable[i])
  29.               {
  30.                       fee+=(hours-hourTable[i])*feeTable[i];
  31.                       hours=hourTable[i];
  32.               }  
  33.        }

  34.         System.out.println("應繳費用:" + fee + "元整");
  35.     }
  36. }
複製代碼

TOP

返回列表