让我先说清楚这是用于分配的。我对编程非常陌生,因此非常感谢所有的指导。我必须计算的计划是停车费为3小时或以下的最低2.00美元,额外每小时0.5美分的停车费,以及每24小时10美元的上限。计划必须显示最近的客户费用以及运行总额。必须初始化常量,必须使用Math.ceil,必须使用方法calculateCharges来解决每个客户的费用。当我尝试运行这个程序时,我会遇到超级错误,当你看到它时你可能会笑,但是我错在哪里?我不是在寻找答案,只是寻找如何正确编写程序的逻辑。请帮忙!Java方法通过/有序逻辑查询
package Parking;
import java.util.Scanner;
public class parking
{
private static final double THREE_HOURS = 2.00;
private static final double PER_HOUR_COST = .50;
private static final double WHOLE_DAY_COST = 10.00;
public static void main (String [] args)
{
double hoursParked = 0;
double cumulativeCharges = 0;
double storage1 = 0;
double storage2 = 0;
Scanner input = new Scanner(System.in);
System.out.print("\nThis program displays the charge for the most recent customer");
System.out.print(" as well as the running total of yesterday's receipts\n");
do
{ System.out.printf("Enter an number between 1-24 for hours parked in garage or -1 to quit:");
hoursParked = input.nextDouble();
}
while((hoursParked > 0)&&(hoursParked <= 24)&&(hoursParked != -1));
if(hoursParked <= 3)
System.out.printf("Most recent customer's charge was: %.2f\n" , THREE_HOURS);
storage1 += THREE_HOURS;
if(hoursParked >= 18.01)
System.out.printf("Most recent customer's charge was:%.2f\n" , WHOLE_DAY_COST);
storage2 += WHOLE_DAY_COST;
double result = calculateCharges(hoursParked * PER_HOUR_COST);
System.out.printf("Most recent customer charge was:%.2f\n" , result);
cumulativeCharges = storage1 + storage2;
System.out.printf("Running total of yesterday's receipts is:%.2f\n" , cumulativeCharges);
} // end main
public static double calculateCharges (double hoursParked)
{
Math.ceil(hoursParked);
double total = hoursParked * PER_HOUR_COST;
return total;
} // end method calculateCharges
} // end class parking
你是什么意思的“超级错误”?他们是编译错误吗?程序是否编译,但运行时会抛出异常?它运行但打印出意外的输出?你需要准确地说出你所看到的错误。错误消息通常会让您很好地指出问题出在哪里。 – 2012-02-13 00:36:36
这只是我尝试运行该程序时看到的冰山一角:用法:javaw [-options] class [args ...] (执行类) 或javaw [-options] -jar jar文件[参数...] (执行jar文件) 其中选项包括: -server \t选择“服务器” VM -hotspot \t为“服务器”的同义词VM(已废弃) 的默认的VM是服务器。 -cp <目录和zip/jar文件的类搜索路径> – Jremy 2012-02-13 00:55:09
这没有帮助,因为我们不知道你在做什么来产生这些错误。 – 2012-02-13 01:08:14