Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is wrong with this portion of the following code \"choice = getChoice(cours

ID: 3882462 • Letter: W

Question

What is wrong with this portion of the following code "choice = getChoice(courses, input);"?

do {

choice = getChoice(courses, input);
  
switch (ValidateChoice(choice, validChoices, totalCredit, courses)) {
case -1:
System.out.println("**Invalid** - Your selection of " +
choice + " is not a recognized course.");
break;
case -2:
System.out.println("**Invalid** - You have already registerd for this " +
courses[0][choice-1] + " course.");
break;
case -3:
System.out.println("**Invalid** - You can not register for more than 9 credit hours.");
break;
case 0:
System.out.println("Registration Confirmed for course " +
courses[0][choice-1] );
totalCredit += Integer.parseInt(courses[1][choice-1]);
if (validChoices[0][0].equals("")) {
validChoices[0][0] = Integer.toString(choice);
validChoices[0] = courses[0][choice-1];
} else if (validChoices[1][0].equals("")) {
validChoices[1][0] = Integer.toString(choice);
validChoices[1][1] = courses[0][choice-1];
} else if (validChoices[2][0].equals("")) {
validChoices[2][0] = Integer.toString(choice);
validChoices[2][1] = courses[0][choice-1];
}
break;
}

Explanation / Answer

Dear Student,

As you have not uploaded the complete Code, however i have tried to correct the code, see the below correction..

-----------------------------------------------------------------------------------------------------------------------------------------

do {

            //I am sure that this getChoice method will return an integer value that will be stored in

            //choice variable

choice = getChoice(courses, input);


//inside switch statement you can call a method, the switch case only accept either an integer , char or boolean value. i.e The expression used in switch must be integral type ( int, char and enum). Any other type of expression is not allowed.

             //change this statement


   //switch (ValidateChoice(choice, validChoices, totalCredit, courses))

           switch(choice)         //this will work fine.

           {

           }

----------------------------------------------------------------------------------------------------------------------------------------

Kindly Check and Verify Thanks...!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote