標題:
TQC+ 507 停車費用計算
[打印本頁]
作者:
顏子翔
時間:
2019-5-18 14:37
標題:
TQC+ 507 停車費用計算
作者:
吳秉翰
時間:
2019-5-18 14:48
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; // 停車費用
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 + "元整");
}
}
複製代碼
作者:
湯東緯
時間:
2019-5-18 14:51
public class JPA507{
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 i=3;i>=0;i--){
if (hours>hourTable[i]){
fee+=(hours-hourTable[i])*feeTable[i];
hours=hourTable[i];
}
}
System.out.println("應繳費用:" + fee + "元整");
}
}
複製代碼
作者:
鄭楀諺
時間:
2019-6-6 20:01
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; //停車費用
if(hours>= 1 && hours <= 2)
{
fee = hours*feeTable[0];
System.out.println("停車時數:"+hours+"小時");
}
if(hours >= 3 && hours <= 4)
{
fee = (hours-hourTable[1])*feeTable[1]+2*feeTable[0];
System.out.println("停車時數:"+hours+"小時");
}
if(hours >= 5 && hours <= 6)
{
fee = (hours-hourTable[2])*feeTable[2]+2*feeTable[1]+2*feeTable[0];
System.out.println("停車時數:"+hours+"小時");
}
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