Answer:
import java.util.Scanner;
public class DeliveryCharges
{
public static void main(String[] args) {
String[] zips = {"01234", "11234", "21234", "31234", "41234", "51234", "61234", "71234", "81234", "91234"};
double[] prices = {2.2, 1.0, 3.6, 6, 9, 7.1, 0.8, 4.7, 3.3, 5.2};
int index = -1;
Scanner ob = new Scanner(System.in);
System.out.print("Enter the zip code for your delivery: ");
String zip = ob.next();
for (int i=0; i<10; i++) {
if (zip.equals(zips[i])) {
index = i;
}
}
if (index!= -1)
System.out.println("Delivery charge to " + zips[index] + " is: " + prices[index]);
else
System.out.println("No delivery to " + zip);
}
}
Step-by-step explanation:
Initialize the zips and prices
Initialize index that represents the index of the zip code. If the entered zip code is in the array
Ask the user to enter the zip code
Create a for loop that iterates through the zips. If the entered zip is in the zips, set its index to index
When the loop is done, check if the index. If the index is not -1, that means zip code was found in the zips array, print the corresponding price from the price array. Otherwise, print no delivery for the entered zip code