Board logo

標題: TQC+ 507 停車費用計算 [打印本頁]

作者: 顏子翔    時間: 2019-5-18 14:37     標題: TQC+ 507 停車費用計算


作者: 吳秉翰    時間: 2019-5-18 14:48

  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. }
複製代碼

作者: 湯東緯    時間: 2019-5-18 14:51

  1. public class JPA507{
  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.   System.out.println("停車時數:" + hours + "小時");
  21.   for(int i=3;i>=0;i--){
  22.    if (hours>hourTable[i]){
  23.     fee+=(hours-hourTable[i])*feeTable[i];
  24.     hours=hourTable[i];
  25.    }           
  26.   }
  27.   System.out.println("應繳費用:" + fee + "元整");
  28. }
  29. }
複製代碼

作者: 鄭楀諺    時間: 2019-6-6 20:01

  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. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2