返回列表 發帖
  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.                 hours = 3;
  8.                 park(hours);
  9.                 System.out.println("--------------------");

  10.                 hours = 5;
  11.                 park(hours);
  12.                 System.out.println("--------------------");

  13.                 hours = 8;
  14.                 park(hours);
  15.         }

  16.         public static void park(int hours) {
  17.                 int[] hourTable = { 0, 2, 4, 6 }; // 時段
  18.                 int[] feeTable = { 30, 50, 80, 100 }; // 時段費率
  19.                 int fee = 0; // 停車費用
  20.                 if (hours >= 1 && hours <= 2) {
  21.                         fee=hours*feeTable[0];
  22.                 }
  23.                 if (hours >= 3 && hours <= 4) {
  24.                         fee=(hours-hourTable[1])*feeTable[1]+2*feeTable[0];
  25.                 }
  26.                 if (hours >= 5 && hours <= 6) {
  27.                         fee=(hours-hourTable[2])*feeTable[2]+2*feeTable[1]+2*feeTable[0];
  28.                 }
  29.                 if (hours >= 7) {
  30.                         fee=(hours-hourTable[3])*feeTable[3]+2*feeTable[2]+2*feeTable[1]+2*feeTable[0];
  31.                 }
  32.                 System.out.println("停車時數:" + hours + "小時");
  33.                 System.out.println("應繳費用:" + fee + "元整");
  34.         }
  35. }
複製代碼

TOP

返回列表