Question

The files provided contain syntax and/or logic errors. In each case, determine and fix the problem,...

The files provided contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.

import 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 = new
StringBuffer("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";
else
message = "Sorry code not found";
System.out.println(message);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import 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 = new StringBuffer(
                "Enter shipping code for this delivery\nValid codes are: ");
        for (int x = 0; x < okayCodes.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 < okayCodes.length; ++i) {
            if (userCode == okayCodes[i]) {
                found = true;
            }
        }
        if (found)
            message = "Good code";
        else
            message = "Sorry code not found";
        System.out.println(message);
    }
}
Add a comment
Know the answer?
Add Answer to:
The files provided contain syntax and/or logic errors. In each case, determine and fix the problem,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // Prompt user for value to start // Value must be between 1 and 20 inclusive // At command line, count down to blastoff // With a brief pause between each displayed value import java.util.*; public class DebugSix3 { public static void...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // Start with a penny // double it every day // how much do you have in a 30-day month? public class DebugSix1 { public static void main(String args[]) { final int DAYS = 30; double money = 0.01; int day =...

  • For the below code find and fix the errors then tell what the output would be....

    For the below code find and fix the errors then tell what the output would be. import java.utils.*; public class pin public void main(String[] args); { char s; int num; Scanner br = Scanner(System.in); System.out.print("Enter the first letter of your name :"); s = BR.next().charAt(0); num = s; System.out.println(“The value associated with your letter is” num); }

  • Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util...

    Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...

  • Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link...

    Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...

  • - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or...

    - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or syntax errors.  Correct the pseudocode and one Java program. Add the corrected code in BOLD and change the corrected color to RED.   Debugging 4:  Add the missing code in bold and red. import java.util.Scanner; public class Airline {             public static void main(String args[])             {                         Scanner s = new Scanner(System.in);                         String passengerName = ""                              String ageString = ""                           int passengerAge = 0                         System.out.println("Enter passenger's name: ");                         passengerName  =...

  • Write an application that displays a series of at least five student ID numbers (that you...

    Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100). Catch the ScoreException, display the message Score over 100, and then store a 0 for the student’s score. At the...

  • Here is the finsihed java program, it just needs to be converted to MIPs assembly language:...

    Here is the finsihed java program, it just needs to be converted to MIPs assembly language: import java.util.*; public class LoveCS { public static void main(String[] args) { int timesMessagePrinted; int count = 0; int sum = 0; Scanner input = new Scanner(System.in); System.out.print("How many times should the message be printed?: "); timesMessagePrinted = input.nextInt(); for(int x = 1; x <= timesMessagePrinted; x++) { System.out.println(x +" I love Computer Science!!"); count++; sum += x; } System.out.print("Printed this message " +count...

  • DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one...

    DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues. //start import java.util.Scanner; public class NumbersDemo {    public static void main (String args[])    {       Scanner kb = new Scanner(System.in);       int num1, num2;             System.out.print("Enter an integer >> ");       num1 = kb.nextInt();       System.out.print("Enter another integer >> ");       num2 = kb.nextDouble();       displayTwiceTheNumber(num1);       displayNumberPlusFive(num1);       displayNumberSquared(num1)       displayTwiceTheNumber(num2);       displayNumberPlusFive(num2);       displayNumberSquared(num2);    }   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT