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

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

  30.         if(hours >= 3 && hours <= 4)
  31.         {
  32.                 fee = (hours-hourTable[1])*feeTable[1]+2*feeTable[0];
  33.                 System.out.println("停車時數:"+hours+"小時");
  34.         }
  35.         
  36.         if(hours >= 5 && hours <= 6)
  37.         {
  38.                 fee = (hours-hourTable[2])*feeTable[2]+2*feeTable[1]+2*feeTable[0];
  39.                 System.out.println("停車時數:"+hours+"小時");
  40.         }
  41.         
  42.         if(hours >=7)
  43.         {
  44.                 fee = (hours-hourTable[3])*feeTable[3]+2*feeTable[2]+2*feeTable[1]+2*feeTable[0];
  45.                 System.out.println("停車時數:"+hours+"小時");
  46.         }
  47.         System.out.println("應繳費用:" + fee + "元整");
  48.     }
  49. }
複製代碼

TOP

返回列表