Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program the displays the State bird and flower. The program should

ID: 641775 • Letter: W

Question

Write a Java program the displays the State bird and flower. The program should prompt the user to enter a State and print both the State bird and flower. The user should be able to enter a State without worrying about case. (e.g. Users could enter Maryland, maryland, MARYLAND or any other possible combination of lower and upper case characters. States may also contain leading and trailing white spaces. Hint: Store the State information in a multidimensional array. The program should continue to prompt the user to enter a state until

Explanation / Answer

//Java program that prompts the name of the state of united
//states and display the bird and flower of the state.
//unitl user enters None to stop reading.
//If invalid state is entered display a message

import java.util.Scanner;
public class StatesInformation
{
   public static void main(String[] args)
   {      

       //Scanner object to read input
       Scanner scanner =new Scanner(System.in);
      
       //store the 50 states birds and flowers in a two dimensional
       //array
       //First column is state name, seconds column is bird name
       //third column is flower name
       String[][] stateInformation=new String[][]
               {
               {"ALABAMA","Yellowhammer","Camelia"},
               {"ALASKA","Willow Ptarmigan","Forget-Me-Not"},
               {"ARIZONA","Cactus Wren","Saguaro Cactus"},
               {"ARKANSAS","Mockingbird","Apple Blossom"},
               {"CALIFORNIA","California Valley Quail","Golden Poppy"},
               {"COLORADO","Lark Bunting","Columbine"},
               {"CONNECTICUT","American Robin","Mountain Laurel"},
               {"DELAWARE","Blue Hen Chicken","Peach Blossom"},
               {"FLORIDA",   "Mockingbird","Orange Blossom"},
               {"GEORGIA","Brown Thrasher","Cherokee Rose"},
               {"HAWAII","Hawaiian Goose","Yellow Hibiscus"},
               {"IDAHO","Mountain Bluebird","Syringa"},
               {"ILLINOIS","Cardinal","Violet"},
               {"INDIANA","Cardinal","Peony"},
               {"IOWA","Eastern Goldfinch","Wild Rose"},
               {"KENTUCKY","Cardinal","Golden Rod"},
               {"KANSAS","Western Meadowlark","Sun Flower"},
               {"LOUISIANA","Brown","Pelican   Magnolia"},
               {"MAINE","Chickadee","Pine Cone"},
               {"MARYLAND","Baltimore Oriole","Black-Eyed Susan"},
               {"MASSACHUSETTS","Chickadee","Mayflower"},
               {"MICHIGAN","Robin Apple","Blossom"},
               {"MINNESOTA","Common Loon","Lady's Slippper"},
               {"MISSISSIPPI","Mockingbird","Magnolia"},
               {"MISSOURI","Bluebird","Hawthorne"},
               {"MONTANA","Western Meadowlark","Bitter Root"},
               {"NEBRASKA","Western Meadowlark","Golden Rod"},
               {"NEVADA","Mountain Bluebird","Sage Brush"},
               {"NEW HAMPSHIRE","Purple Finch","Lilac"},
               {"NEW JERSEY","Eastern Goldfinch","Violet"},
               {"NEW MEXICO","Roadrunner","Yucca"},
               {"NEW YORK","Bluebird","Rose"},
               {"NORTH CAROLINA","Cardinal","Dogwood"},
               {"NORTH DAKOTA","Western Meadowlark","Wild Rose"},
               {"OKLAHOMA,Scissortailed Flycatcher,Mistletoe"},
               {"OHIO","Cardinal","Carnation"},
               {"OREGON","Western Meadowlark","Oregon Grape"},
               {"RHODE ISLAND","Rhode Island Red","Violet"},
               {"PENNSYLVANIA","Ruffed Grouse","Mountain Laurel"},
               {"SOUTH CAROLINA","Carolina Wren","Yellow Jessamine"},
               {"SOUTH DAKOTA","Ring-necked Pheasant","Pasque Flower"},
               {"TENNESSEE","Mockingbird","Iris"},
               {"TEXAS","Mockingbird","Blue Bonnet"},
               {"UTAH","California Seagull","Sego Lily"},
               {"VERMONT","Hermit Thrush","Red Clover"},
               {"VIRGINIA,Cardinal,Dogwood"},
               {"WASHINGTON","Willow Goldfinch","Rhododendrum"},
               {"WEST VIRGINIA   ","Cardinal","Big Laurel"},
               {"WISCONSIN   ","Robin","Violet"},
               {"WYOMING","Meadowlark","Indian Paint Brush"}
               };

       //read state birds and flowers in a two dimensional array
       while(true)
       {

           System.out.println("Enter a State or None to exit:");
           String stateName=scanner.nextLine();

           if(stateName.equals("None"))
               System.exit(0);
           else
           {

               int position=getBirdFlower(stateInformation, stateName);
               if(position!=-1)
               {
                   System.out.println("Bird: "+stateInformation[position][1]);
                   System.out.println("Flower: "+stateInformation[position][2]);              
               }
               else
                   System.out.println("Invalid state entered");
           }

       }
   }

   public static int getBirdFlower(String stateInfo[][],String state)
   {
       int position=-1;
       boolean found=false;
       for (int index = 0; index < stateInfo.length && !found; index++)
       {
           if(stateInfo[index][0].equalsIgnoreCase(state))
               position=index;              
       }

       return position;
   }


}//end of the class


--------------------------------------------------------------------------------------------------------------------------------

Sample output:

Enter a State or None to exit:
Maryland
Bird: Baltimore Oriole
Flower: Black-Eyed Susan
Enter a State or None to exit:
Delaware
Bird: Blue Hen Chicken
Flower: Peach Blossom
Enter a State or None to exit:
None

Hope this helps you..

//Note : The program is changed as per your requirements completely.

//Please check with results.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote