標題:
507-停車費用計算
[打印本頁]
作者:
許承鴻
時間:
2018-10-2 18:40
標題:
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; //停車費用
...
System.out.println("應繳費用:" + fee + "元整");
}
}
複製代碼
作者:
巫沛庭
時間:
2018-10-2 19:31
package text;
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; //停車費用
for(int i=3;i>=0;i--)
{
if(hours>hourTable[i])
{
fee+=(hours-hourTable[i])*feeTable[i];
hours=hourTable[i];
}
}
System.out.println("應繳費用:" + fee + "元整");
}
}
複製代碼
作者:
巫晉宇
時間:
2018-10-2 19:51
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 + "元整");
}
}
作者:
張閎鈞
時間:
2018-10-2 20:08
package hi87;
public class hi78 {
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;
System.out.println("停車時數:"+hours+"小時");
for(int a=3;a>=0;a--)
{
if(hours>hourTable[a])
{
fee+=(hours-hourTable[a])*feetable[a];
hours=hourTable[a];
}
}
System.out.println("應繳費用"+fee+"元整");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2