yes, this is my homework. But i am stuck and have been for days. (horrible teacher, horrible lessons. this teacher will never respond to me or anyone about anything)
I have seen something like this on here before but never seen or understood their answers.
In this program, the user inputs a state, then it outputs the states bird and its flower. after the user types none, it should give them a summery of everything they typed in a row. State, Bird, Flower. I have not a clue how to do this... You do not have to tell me how, that is fine. but could you please guide me, in a non vague way haha.
import java.util.Scanner;
public class TheStatesTester {
public static void main(String[] args) {
String theState [][] = {
{"Alabama", "Northern Flicker","Camelia"},
{"Alaska", "Willow PTarmigan","ForgetMeNot"},
{"Arizona", "Cactus Wren","Saguaro Cactus Blossom"},
{"Arkansas", "Mockingbird","Apple Blossom"},
{"California", "California Quail","California Blossom"},
{"Colorado", "Lark Bunting","Rocking Mountain Columbine"},
{"Connecticut", "American Robin","Mountain Laurel"},
{"Delaware", "Blue Hen Chicken","Peach Blossom"},
{"Flordia", "Mockingbird","Orange Blossom"},
{"Georgia", "Brown Thrasher","Cherokee Rose"},
{"Hawaii", "Nene","Hibiscus"},
{"Idaho", "Peregrine Falcon","Mock Orange"},
{"Illinois", " Northern Cardinal","Purple Violet"},
{"Indiana", "Northern Cardinal","Peony"},
{"Iowa", "Eastern Goldrinch","Wild Prairie Rose"},
{"Kansas", "Western Meadowlark","Sunflower"},
{"Kentucky", "Northen Cardinal","Golden Rod"},
{"Louisiana", "Brown Pelican","Magnolia"},
{"Maine", "Black-capped Chickadee","White Pine Tassel and Cone"},
{"Maryland", "Baltimore Oriole","Black-Eyes Susan"},
{"Massachusetts", "Black-Capped Chickadee","Mayflower"},
{"Michigan", "Robin Redbreast","Apple Blossom"},
{"Minnesota", "Common Loon","Pink and White ladyslipper"},
{"Mississippi", "Wood Duck","Magnolia"},
{"Missouri", "Eastern Bluebird","Hawthorn"},
{"Montana", "Western Meadowlark","Bitterroot"},
{"Nebraska", "Western Medowlark","Goldenrod"},
{"Nevada", "Mountain Bluebird","Sagebush"},
{"New Hampshire", "Purple Finch","Purple Lilac"},
{"New Jersey", "Eastern Goldfinch","Violet"},
{"New Mexico", "Roadrunner","Yucca"},
{"New York", "Bluebird","Rose"},
{"North Carolina", "Cardinal","Flowering Dogwood"},
{"North Dakota", "Western Meadowlark","Wild Prairie Rose"},
{"Ohio", "Cardinal","Scarlet Carnation"},
{"Oklahoma", "Scissor-tailed Flycatcher","Mistletoe"},
{"Oregon", "Western Medowlark","Orange Grape"},
{"Pennsylvania", "Ruffed Grouse","Mountain Laurel"},
{"Rhode Island", "Rhode Island Red","Violet"},
{"South Carolina", "Great Carolina Wren","Yellow Jessamine"},
{"South Dakota", "Ring-necked Pheasant","Pasque Flower"},
{"Tennessee", "Mocking Bird","Iris"},
{"Texas", "Mocking Bird","Texas Bluebonnet"},
{"Utah", "Common American Gull","Sego Lily"},
{"Vermont", "Hermit Thrush","Red Clover"},
{"Virginia", "Cardinal","Flowering Dogwood"},
{"Washington", "Willow Goldfinch","Coast Rhodoendron"},
{"West Virginia", "Cardinal","Rhododendron"},
{"Wisconsin", "Robin","Violet"},
{"Wyoming", "Western Medowlark","Indian Paintbrush"},
};
Scanner input1 = new Scanner(System.in);
while (true) {
System.out.println("Enter a State or None to exit: ");
String states = input1.nextLine();
int position=getBirdFlower(theState, states);
if (states.trim().equalsIgnoreCase("None")){
System.out.println("**** Thank you *****\r\n" +
"A summary report for each State, Bird, and Flower is: " );
break;
}
else {
if(position!=-1)
{
System.out.println("Bird: "+theState[position][1]);
System.out.println("Flower: "+theState[position][2]);
}
else
System.out.println("Invalid state entered");
// for (int i=0; i<state.length;i)
// for (int j=0;j<state[i].length;j)
// System.out.println(state[i][j]);
}
}
}
public static int getBirdFlower(String theState[][], String state)
{
int position = -1;
boolean found=false;
for (int index = 0; index < theState.length && !found; index++)
{
if(theState[index][0].equalsIgnoreCase(state))
position = index;
}
return position;
}
}
getBirdFlower()which should be renamed as it doesn't return the bird and flower data but an index into the data. Hints:foundis only set once (so it can't change totrue) but you do not really need the variable at all; you can place multiplereturns in a function (if it makes sense), also inside a for-loop which is then exited at the return.