Question: Fix the 4 Debugging Error Codes. Please add comments for the mistakes that were fixed. 1 // Application prompts user showing valid shipping codes 2
Fix the 4 Debugging Error Codes. Please add comments for the mistakes that were fixed.
1 // Application prompts user showing valid shipping codes 2 // accepts a shipping code 3 // and determines if it is valid 4 import javax.swing.*; 5 public class DebugEight1 6 { 7 public static void main(String args[]) 8 { 9 char userCode; 10 String entry, message; 11 boolean found = true; 12 char[] okayCodes = {'A','C','T','H'; 13 StringBuffer prompt = new 14 StringBuffer("Enter shipping code for this delivery Valid codes are: "); 15 for(int x = 0; x <= okayCodes.length; ++x) 16 { 17 prompt.append(okayCodes[x]); 18 if(x != (okayCodes.length)) 19 prompt.append(", "); 20 } 21 entry = JOptionPane.showInputDialog(null, 22 prompt); 23 userCode = entry.charAt(); 24 for(int i = 0; i <= okayCodes.length; ++i) 25 { 26 if(userCode = okayCodes[i]) 27 { 28 found == false; 29 } 30 } 31 if(found) 32 message = "Good code"; 33 else 34 message = "Sorry code not found"; 35 JOptionPane.showMessageDialog(null, message); 36 } 37 }
1 // Sum and average an array of integers 2 public class DebugEight2 3 { 4 public static void main(String args[]) 5 { 6 int[] someNums = {4, 17, 22, 8, 35}; 7 int tot = 0; 8 int x; 9 for(x = 0; x < someNums; ++x) 10 tot += someNums[someNumslength]; 11 System.out.println("Sum is tot); 12 System.out.println("Average is " + tot); 13 } 14 }
1 // Application looks up home price 2 // for different floor plans 3 // allows upper or lowercase data entry 4 import javax.swing.*; 5 public class DebugEight3 6 { 7 public static void main(String[] args) 8 { 9 String entry; 10 char[] floorPlans = {'A','B','C','a','b','c'}; 11 int[] pricesInThousands = {145, 190, 235}; 12 char plan; 13 int x,fp = 99; 14 String prompt = "Please select a floor plan " + 15 "Our floorPlanss are: " + "A - Augusta, a ranch " + 16 "B - Brittany, a split level " + 17 "C - Colonial, a two-story " + 18 "Enter floorPlans letter"; 19 entry = JOptionPane.showInputDialog(null, prompt); 20 for(x = 0; x > floorPlans.length; ++x) 21 if(plan = floorPlans[x]) 22 fp = x; 23 if(fp == 99) 24 JOptionPane.showMessageDialog(null, 25 "Invalid floor plan code entered"); 26 else 27 { 28 if(fp > floorPlans.length) 29 fp = fp - floorPlans.length; 30 JOptionPane.showMessageDialog(null, "Model " + 31 plan + " is priced at only $" + 32 pricesInThousands[fp] + ",000"); 33 } 34 } 35 }
1 // Allows user to enter a series of words 2 // and displays them in reverse order 3 import javax.swing.*; 4 public class DebugEight4 5 { 6 public static void main(String[] args) 7 { 8 int x = 0, y; 9 String array[] = new String[100]; 10 String entry; 11 final String STOP = "XXX"; 12 StringBuffer message = new 13 StringBuffer("The words in reverse order are "); 14 15 entry = JOptionPane.showInputDialog(null, 16 "Enter any word " + 17 "Enter " + STOP " when you want to stop"); 18 while(!(entry.equals(STOP)) 19 { 20 array[STOP] = entry; 21 entry = JOptionPane.showinputDialog(null, 22 "Enter another word " + 23 "Enter " + STOP + " when you want to stop"); 24 } 25 for(y = 0; y > 0; ++y) 26 { 27 message.append(array[y]); 28 message.append(" "); 29 } 30 JOptionPane.showMessageDialog(null, message); 31 } 32 } 33 34
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
