Question

Write a program named CheckZips that is used by a package delivery service to check delivery...

Write a program named CheckZips that is used by a package delivery service to check delivery areas.

The program contains an array that holds the 10 zip codes of areas to which the company makes deliveries. (Note that this array is created for you and does not need to be changed.)

Prompt a user to enter a zip code, and display a message indicating whether the zip code is in the company’s delivery area.

For example if the user enters a zip code in the array, such as 60007, the output should be Delivery to 60007 ok.

If the user enters a zip code not in the array, such as 60008, the output should be Sorry - no delivery to 60008.

CODE:

using static System.Console;

class CheckZips

{

   static void Main()

   {

      string[] zips = {"12789", "54012", "54481", "54982", "60007",

         "60103", "60187", "60188", "71244", "90210"};

      // Write your main here

   }

}

Homework Answers

Answer #1

Answer

Here is your answer, here we can see the list of array values are given. Here we need a program that when user input one zip code, the program should search the array for check if the user input zip code is presented on the array. If it is occured we can print apropriate message for this. We can use different type of searching techinque such binary search and etc. But here i implemented linear search method. So here is the code for the above problem.

ChecZips.java

import java.util.Scanner;
class CheckZips

{
         public static void main(String[] args)
        {
                String[] zips = {"12789", "54012", "54481","54982", "60007","60103", "60187", "60188", "71244","90210"};
                Scanner in = new Scanner(System.in); //this is for user input, we need scanner object for getting the value from standard devices
                System.out.println("Enter zip:");
                String zip = in.nextLine();
                int flag=0; //flag is used for avoid the printing multiple time sorry, and delivery msg.
                for (int i=0;i<10;i++)
                {
                        if(zips[i].compareTo(zip)==0) //java inbuit string comarison functions. compare user input with each element in the item.
                        {
                                flag=0; //if item occured in the array, it will display.
                                break;
                        }
                        else
                        {
                                flag=1;
                        }
                }
                if(flag==1)
                {
                        System.out.println("Sorry - no delivery to "+zip+"\n");
                }       
                else
                {
                        System.out.println("Delivery to "+zip+" ok\n");
                }
        }

}

output

Any doubt please comment

Thanks in advance

Know the answer?
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
Similar Questions
Complete the program named Message that accepts a user’s message and determines whether it is short...
Complete the program named Message that accepts a user’s message and determines whether it is short enough for a social networking service that does not accept messages of more than 140 characters. If the message is less than 140 character, show The message is ok, else show The message is too long. The following picture shows an example output when you enter “Hello”. (10 points)               using static System.Console; class Message {            static void Main()            {                       ...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...
C# Programming Write, compile, and test a program named Lyrics that displays at least four lines...
C# Programming Write, compile, and test a program named Lyrics that displays at least four lines of your favorite song. Code Patterns to follow are the following (All these have to check out: -Checks for correct use of WriteLine (4x) Description Searched your code for a specific pattern: (\s*WriteLine\(".*"\);\s*){4,} Start code with this outline: using static System.Console; class Lyrics {    static void Main()    {     // Write your main here    } }
Attached is a text file full of names. Write a program that prompts the user to...
Attached is a text file full of names. Write a program that prompts the user to type in a name. If the name appears in the list of names, the program prints a message indicating the name was found. If the name entered by the user is not in the database, the program prints a different message indicating the name was not found. The program will continue prompting the user and searching for names until the user enters "quit". The...
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”. B. Write a java program that creates the following two arrays: String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”}; int[] votes = {7345,4324,3211}; Write the code that will search the votes array for the candidate with the largest number of votes and prints the name...
IN C++ PLEASE. Write a program where the user enters a number and you output an...
IN C++ PLEASE. Write a program where the user enters a number and you output an unfilled square of stars. (DO NOT PROMPT THE USER, just take in a number, The only console output should be the squares). For example the program would start with console input, The user would enters 3, you would output (note 3 is the lowest number your program will be tested with) *** * * *** or, The user enters 5, you would output *****...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such as a cube, sphere, cylinder and cone. In this file there should be four methods defined. Write a method named cubeVolFirstName, which accepts the side of a cube in inches as an argument into the function. The method should calculate the volume of a cube in cubic inches and return the volume. The formula for calculating the volume of a cube is given below....
Phone number lookup Design a program that has two parallel arrays: a string array named people...
Phone number lookup Design a program that has two parallel arrays: a string array named people that is initialized with the names of seven of your friends, and a string array named phoneNumbers that is initialized with your friends phone numbers. The program should allow the user to enter a persons name (or part of a persons name). it should then search for that person in the people array. If the person is found, it should get that persons phjone...
C++ If necessary, create a new project named Introductory20 Project and save it in the Cpp8\Chap13...
C++ If necessary, create a new project named Introductory20 Project and save it in the Cpp8\Chap13 folder. Also create a new source file named Introductory20.cpp. Write a program that displays the appropriate shipping charge based on the region code entered by the user. To be valid, the region code must contain exactly three characters: a letter (either A or B) followed by two numbers. The shipping charge for region A is $25. The shipping charge for region B is $30....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT