嗨,大家好,我是一名新的計算機科學專業的學生,我試圖調用一種方法,並且一直在收到此錯誤。這裏是我的問題區域:錯誤:無效的方法聲明;返回類型ERROR在調用方法時
calcTicket(String driverName, int speedDriving, int speedLimit, String schoolZone);
這裏是整個代碼(這不是太長):
import java.util.Scanner;
public class SpeedingTicket
{
public static void main(String[] args)
//Declarations and Instantiations
{
// Input Data
Scanner scan = new Scanner(System.in);
System.out.println("Enter driver's name: ");
String driverName = scan.nextLine();
System.out.println("Enter driver's speed: ");
int speedDriving = scan.nextInt();
System.out.println("Enter speed limit: ");
int speedLimit = scan.nextInt();
scan.nextLine();
System.out.println("Was driver in school zone? ");
String schoolZone = scan.nextLine();
}
// Call calcTicket
calcTicket(String driverName, int speedDriving, int speedLimit, String schoolZone);
/** Calculates the cost of a speeding ticket given the speed driven, limit, and if in a school zone.
*/
public static void calcTicket(String driverName, int speedDriving, int speedLimit, String schoolZone)
{
// Define constants here
final int INIT_ADDITIVE = 50;
final int NO_MULTIPLIER = 6;
final int YES_MULTIPLIER = 12;
final int MAX_ADDITIVE = 200;
final int EX_THRESH = 30;
// Calculations
int amountOver = (speedDriving - speedLimit);
if (schoolZone.equalsIgnoreCase("yes"))
{
if (amountOver > 0)
{ int fine = amountOver * YES_MULTIPLIER + INIT_ADDITIVE;
System.out.println(driverName +"owes: $" + fine);
}
if (amountOver > EX_THRESH)
{ int fine = amountOver * YES_MULTIPLIER + MAX_ADDITIVE;
System.out.println(driverName +"owes: $" + fine);
}
else
{ int fine = 0;
System.out.println(driverName +"owes: $" + fine);
}
}
if (schoolZone.equalsIgnoreCase("no"))
{
if (amountOver > 0)
{ int fine = amountOver * NO_MULTIPLIER + INIT_ADDITIVE;
System.out.println(driverName +"owes: $" + fine);
}
if (amountOver > EX_THRESH)
{ int fine = amountOver * NO_MULTIPLIER + MAX_ADDITIVE;
System.out.println(driverName +"owes: $" + fine);
}
else
{ int fine = 0;
System.out.println(driverName +"owes: $" + fine);
}
}
}
}