Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

// Application lists valid shipping codes

// then prompts user for a code

// Application accepts a shipping code

// and determines if it is valid

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 Valid 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);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions