Can I have some help debugging this exercise:// Application lists valid shipping codes// then prompts user for a code// Application accepts a shipping code// and determines if it is validimport java.util.*;public class DebugEight1{public static void main(String args[]){Scanner input = new Scanner(System.in);char userCode;String entry, message;boolean found = false;char[] okayCodes = {'A''C''T''H'};StringBuffer prompt = newStringBuffer("Enter shipping code for this delivery\nValid codes are: ");for(int x = 0; x < length; ++x){prompt.append(okayCodes[x]);if(x != (okayCodes.length - 1))prompt.append(", "); }System.out.println(prompt);entry = input.next();userCode = entry.charAt(0);for(int i = 0; i < length; ++i){if(userCode = okayCodes){found = true;}}if(found)message = "Good code";elsemessage = "Sorry code not found";System.out.println(message);}}

Respuesta :

Answer:

See Explanation

Explanation:

The following lines of codes were corrected.

Note only lines with error are listed out

char[] okayCodes = {'A''C''T''H'};

corrected to

char[] okayCodes = {'A','C','T','H'};

StringBuffer prompt = newStringBuffer("Enter shipping code for this delivery\nValid codes are: ");

corrected to

StringBuffer prompt = new StringBuffer("Enter shipping code for this deliveryValid codes are: ");

for(int x = 0; x < length; ++x)

corrected to

for(int x = 0; x < okayCodes.length; ++x)

for(int i = 0; i < length; ++i)

corrected to

for(int i = 0; i < okayCodes.length; ++i)

if(userCode = okayCodes)

corrected to

if(userCode == okayCodes[i])

if(found)message = "Good code";elsemessage = "Sorry code not found";

corrected to

if(found)

message = "Good code";

else

message = "Sorry code not found";

However, I've added the full source code as an attachment

Ver imagen MrRoyal