I need help with the java programming keeps getting an error message on the firs
ID: 3721949 • Letter: I
Question
I need help with the java programming keeps getting an error message on the first line.
public static int ValidateChoice(int choice, String[][] validChoices, int totalCredit, String[][] courses) {
String choiceAsString = Integer.toString(choice);
if (choice < 1 || choice > 7)
return -1;
else if (choiceAsString.equals(validChoices[0][0])
|| choiceAsString.equals(validChoices[1][0])
|| choiceAsString.equals(validChoices[2][0]))
return -2;
else if ( totalCredit + Integer.parseInt(courses[1][choice-1]) > 9)
return -3;
return 0;
}
Explanation / Answer
Hi,
You miss the class declaration.
=========================================================
public class DerivativeChoise{
public static int ValidateChoice(int choice, String[][] validChoices, int totalCredit, String[][] courses) {
String choiceAsString = Integer.toString(choice);
if (choice < 1 || choice > 7)
return -1;
else if (choiceAsString.equals(validChoices[0][0])
|| choiceAsString.equals(validChoices[1][0])
|| choiceAsString.equals(validChoices[2][0]))
return -2;
else if ( totalCredit + Integer.parseInt(courses[1][choice-1]) > 9)
return -3;
return 0;
}
}
=============================================================
Please save file as DerivativeChoise.java .you can compile file as javac DerivativeChoise.java .
OUTPUT: No compilation Errors
NOTE: You need to add main() method to the class as per your requirement. Your requirement is not Clear in the question.