Question: How do I get this into two separate java files, one as a DataEntryClass that provides the information for the program, and another TestClass that
How do I get this into two separate java files, one as a DataEntryClass that provides the information for the program, and another TestClass that runs the program?
//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 States { 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
