Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 24, 2017 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/a77b467076af14c0a60d533e791fe8ef to your computer and use it in GitHub Desktop.
Save peter279k/a77b467076af14c0a60d533e791fe8ef to your computer and use it in GitHub Desktop.
TQC+ JAVA
public class JPA05 {
public static void main(String[] argv) {
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; //停車費用
System.out.println("停車時數:" + hours);
for(int index=hourTable.length-1;index>=0;index--) {
if(hours - hourTable[index] > 0) {
fee += (hours - hourTable[index]) * feeTable[index];
hours -= (hours - hourTable[index]);
}
}
System.out.println("應繳費用:" + fee + "元整");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment