標題:
TQC+ 507 停車費用計算
[打印本頁]
作者:
周政輝
時間:
2017-7-8 11:48
標題:
TQC+ 507 停車費用計算
public class JPD05 {
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; //停車費用
if(hours>=1 && hours<=2)
fee+=hours*feeTable[0];
if(hours>=3 && hours<=4)
fee+=(hours-hourTable[1])*feeTable[1]+2*feeTable[0];
if(hours>=5 && hours<=6)
fee+=(hours-hourTable[2])*feeTable[2]+2*feeTable[1]+2*feeTable[0];
if(hours>=7)
fee+=(hours-hourTable[3])*feeTable[3]+2*feeTable[2]+2*feeTable[1]+2*feeTable[0];
System.out.println("停車時數:"+hours+"小時");
System.out.println("應繳費用:" + fee + "元整");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2