返回列表 發帖

507-停車費用計算

  1. public class JPD05 {
  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.         ...

  26.         System.out.println("應繳費用:" + fee + "元整");
  27.     }
  28. }
複製代碼
Stay hungry,
Stay foolish.

  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

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 + "元整");
        }

}

TOP

  1. package hi87;

  2. public class hi78 {

  3.         public static void main(String[] args) {
  4.                 // TODO 自動產生的方法 Stub
  5. int hours=0;

  6. hours=2;
  7. park(hours);
  8. System.out.println("");
  9. hours=3;
  10. park(hours);
  11. System.out.println("");

  12. hours=5;
  13. park(hours);
  14. System.out.println("");
  15. hours=8;
  16. park(hours);
  17.         }




  18. public static void park(int hours)
  19. {
  20. int[]hourTable={0,2,4,6};
  21. int[] feetable={30,50,80,100};
  22. int fee=0;

  23. System.out.println("停車時數:"+hours+"小時");
  24.         for(int a=3;a>=0;a--)
  25.         {
  26.                 if(hours>hourTable[a])
  27.                 {
  28.                         fee+=(hours-hourTable[a])*feetable[a];
  29.                         hours=hourTable[a];
  30.                 }
  31.                
  32.                
  33.                
  34.                
  35.         }
  36. System.out.println("應繳費用"+fee+"元整");

  37. }
  38. }
複製代碼
張閎鈞OuO

TOP

返回列表