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()            {                       ...
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    } }
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
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...
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...
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 a Java program that calculates and displays the Fibonacci numbers * First prompt the...
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the user to input a number, N * Then use a for loop to calculate and display the first N fibonocci numbers * For example, if the user enters 5, the output should be: * 1, 1, 2, 3, 5 * * if the user enters 10, the output should be: * 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
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....
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the...
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the following problem: The heating system in a school should be switched on if the average temperature is less than 17 degrees Celsius. The average temperature is found from the temperatures in the Math, English and IT departments. You are required to write a program that allows the user to input 3 temperatures. The program calculates and displays the average temperature and then displays "heating...