Programming Homework Help

Rutgers Debug the Code

 

db6-1. Fix the errors on the attached debug exercise 6-1. There could be syntax and logic errors. You want to check the validity of an inputted code. Pay particular attention to the array and the for loops. Save as db61.java, attach your completed file and submit.

/* d61.java

program accepts shipping codes (uppercase or lowercase)
and determines validity
*/
public class d61
{
	public static void main(String[] args) throws Exception
	{
		int i;
		boolean found = 0;
		char letter;
		char[] okaycodes = {A, C, T, H};
		System.out.printf("A - airnC - carnT - trucknH - hand delivern");
		System.out.printf("Enter shipping code:  ");
		letter = (char)System.in.read();
		for(i = 0; i < 5; i++)
		{
 			if(letter == okaycodes)
 			{
		      	System.out.println("Good code");
		      	found;
			}
	    	else
				System.out.println("Code not found");
		}
		if (!found)
   			System.out.println("Code not found");
	}
}