metrostate.learn minnstate.edu Program #2-Due Sept 25 can I get the user input i
ID: 3750006 • Letter: M
Question
metrostate.learn minnstate.edu Program #2-Due Sept 25 can I get the user input i Platform SE 7 Welcome to Java for Java On Eclispe O write a program that a Requirements Write a program that accepts a zip code as an input and displays information corresponding to that zip code. The output must include the matching city and state. You must also display the county and one additional fact about that zip code. You can find all kinds of interesting zip code information at this website: Your program should include at least 7 valid zip codes with corresponding information. You may not use any of the zip codes I provided as samples on this handout. When the user enters a zip code, check to be sure that it has exactly 5 digits and that it is not a value less than 0. If an error occurs, display an informative message and prompt the user for input again Implement your program using a sentinel controlled loop. This means that you will continue to loop, asking for fresh zip codes and displaying the corresponding information, until a special value is entered You will need to figure out what special value does not correspond to a real zip code Your output must look attractive The program must display your name when it runs Comments and Style Comment your code. At the top of the program include your name, a brief description of the program and what it does and the due date All blocks must be indented consistently and correctly. Blocks are delimited by opening and closing curly bracesExplanation / Answer
ZipCodes.java
import java.util.Scanner;
public class ZipCodes {
public static void main(String[] args) {
//Declaring variables
int pincodes[]={35004,30002,97001,20588,87001,50001,43001};
String cities[]={"Alexandria","Lewis Center","Adelphi","Lockbourne","Lacarne","Ney","OhiLaings"};
String county[]={"St.Clair County","Wasco County","Howard County","Shelby County","Warren County","Madison County","Licking County"};
String info[]={"The percentage of children under 18 living in the ZIP code is slightly higher than average compared to other areas of the country",
"The people living in ZIP code 35010 are primarily white",
"The percentage of children under 18 living in the ZIP code is slightly less than average compared to other areas of the country.",
"Homes in ZIP code were primarily built in the 1950s",
"Homes in ZIP code were primarily built in the 1990s",
"The median home value of $125,500 in ZIP code is slightly less than average compared to the rest of the country",
"Homes in ZIP code 35763 were primarily built in the 2000s"};
int code;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
while(true)
{
//Getting the input entered by the user
System.out.print("Enter zipcode:");
code=sc.nextInt();
if(code<0)
{
System.out.println("** Invalid.Must be 5 digit Positive number **");
}
else if(code<10000 || code>99999)
{
System.out.println("** Invalid.Must be 5 digit number **");
}
else
{
break;
}
}
int indx=checkPinCode(pincodes,code);
if(indx!=-1)
{
System.out.println(cities[indx]+", "+pincodes[indx]);
System.out.println(cities[indx]+" is in "+county[indx]);
System.out.println(info[indx]);
}
else
{
System.out.println("No Data available");
}
}
private static int checkPinCode(int[] pincodes, int code) {
for(int i=0;i<pincodes.length;i++)
{
if(code==pincodes[i])
return i;
}
return -1;
}
}
_________________
Output#1:
Enter zipcode:-3344
** Invalid.Must be 5 digit Positive number **
Enter zipcode:35004
Alexandria, 35004
Alexandria is in St.Clair County
The percentage of children under 18 living in the ZIP code is slightly higher than average compared to other areas of the country
________________
Output#2:
Enter zipcode:20588
Lockbourne, 20588
Lockbourne is in Shelby County
Homes in ZIP code were primarily built in the 1950s
_________________
Output#3:
Enter zipcode:43001
OhiLaings, 43001
OhiLaings is in Licking County
Homes in ZIP code 35763 were primarily built in the 2000s
_______________
Output#4:
Enter zipcode:45324
No Data available
_______Could you plz rate me well.Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.