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

States new hampshire, new york not working.please help import java.util.Scanner;

ID: 3576685 • Letter: S

Question

States new hampshire, new york not working.please help

import java.util.Scanner;

public class Map {

    public static int getInfo(String stateInfo[][], String state) {

        int i = -1;

        boolean found = false;

        for (int index = 0; index < stateInfo.length && !found; index++) {

            if (stateInfo[index][0].trim().equalsIgnoreCase(state))

                i = index;

        }

        return i;

    }

    public static void main(String[] args) {

        Scanner dataInput = new Scanner(System.in);

        //state and Population value

        String[][] stateInformation = new String[][]{

                {"Alabama", "Yellowhammer", "Camellia"},

                {"Alaska", "Willow Ptarmigan", "Forget-me-not"},

                {"Arizona", "Cactus Wren", "Saguaro Cacus Blossom"},

                {"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", "Nene", "Hibiscus"},

                {"Idaho", "Mountain Bluebird", "Syringa"},

                {"Illinois", "Cardinal", "Native violet"},

                {"Indiana", "Cardinal", "Peony"},

                {"Iowa", "Eastern Goldfinch", "Wild Rose"},

                {"Kansas", "Western Meadowlark", "Native Sunflower"},

                {"Kentucky", "Kentuky Cardinal", "Goldenrod"},

                {"Louisiana", "Pelican", "Magnolia"},

                {"Maine", "Augusta", "White Pine Cone and Tassel"},

                {"Maryland", "Baltimore Oriole", "Black-Eyed Susan"},

                {"Massachusetts", "Chickadee", "Mayflower"},

                {"Michigan", "Robin", "Apple Blossom"},

                {"Minnesota", "Common Loon", "Pink and White Lady's Slipper"},

                {"Mississippi", "Mockingbird", "Magnolia"},

                {"Missouri", "Bluebird", "Hawthorn"},

                {"Montana", "Western Meadowlark",    "Bitterroot"},

                {"Nebraska", "Western Meadowlark", "Goldenrod"},

                {"Nevada", "Mountain Bluebird", "Sagebrush"},

                {"New Hampshire", "Purple Finch", "Purple Lilac"},

                {"New Jersey", "Eastern Goldfinch", "Purple Violet"},

                {"New Mexico", "Roadrunner", "Yuca Flower"},

                {"New York", "Bluebird", "Rose"},

                {"North Carolina", "Cardinal", "Dogwood"},

                {"North Dakota", "Western Meadowlark", "Wild Prairier Rose"},

                {"Ohio", "Cardinal", "Scarlet Carnation"},

                {"Oklahoma", "Scissor-Tailed Flycatcher", "Mistletoe"},

                {"Oregon", "Western Meadowlark", "Oregon Grape"},

                {"Pennsylvania", "Ruffed Grouse", "Mountain Laurel"},

                {"Rhode Island", "Rhode Island Red", "Violet"},

                {"South Carolina", "Carolina Wren", "Yellow Jessamine"},

                {"South Dakota", "Ring-Neckked Pheasant", "American Pasqueflower"},

                {"Tennessee", "Mockingbird", "Iris"},

                {"Texas", "Mockingbird", "Bluebonnet"},

                {"Utah", "California Gull", "Sego Lily"},

                {"Vermont", "Hermit Thrush", "Red Clover"},

                {"Virginia", "Cardinal", "Dogwood"},

                {"Washington", "Willow Goldfinch", "Western Rhododendron"},

                {"West Virginia", "Cardinal", "Big Rhododendron"},

                {"Wisconsin", "Robin", "Wood Violet"},

                {"Wyoming", "Meadowlark", "Indian Paintbrush"},

        };

        while (true) {

            System.out.println("Enter a State or None to exit:");

            String stateName = dataInput.next();

            if (stateName.trim().equalsIgnoreCase("None")) {

                System.exit(0);

            } else {

                int i = getInfo(stateInformation, stateName);

                if (i != -1) {

                    System.out.println("Bird: " + stateInformation[i][1]);

                    System.out.println("Flower: " + stateInformation[i][2]);

                } else {

                    System.out.println("Not A Valid State");

                }

            }

        }

    }

}

Explanation / Answer

/* MapTest */

package com.Collections;
import java.util.Scanner;
public class MapTest {


public static int getInfo(String stateInfo[][], String state) {
int i = -1;
boolean found = false;

   for (int index = 0; index < stateInfo.length; index++){
       for (int j = 0; j < 3; j++)
       if (stateInfo[index][j].equalsIgnoreCase(state))
           i = index;
  
}
return i;
}

public static void main(String[] args) {
Scanner dataInput = new Scanner(System.in);
//state and Population value
String[][] stateInformation = new String[][]{
{"Alabama", "Yellowhammer", "Camellia"},
{"Alaska", "Willow Ptarmigan", "Forget-me-not"},
{"Arizona", "Cactus Wren", "Saguaro Cacus Blossom"},
{"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", "Nene", "Hibiscus"},
{"Idaho", "Mountain Bluebird", "Syringa"},
{"Illinois", "Cardinal", "Native violet"},
{"Indiana", "Cardinal", "Peony"},
{"Iowa", "Eastern Goldfinch", "Wild Rose"},
{"Kansas", "Western Meadowlark", "Native Sunflower"},
{"Kentucky", "Kentuky Cardinal", "Goldenrod"},
{"Louisiana", "Pelican", "Magnolia"},
{"Maine", "Augusta", "White Pine Cone and Tassel"},
{"Maryland", "Baltimore Oriole", "Black-Eyed Susan"},
{"Massachusetts", "Chickadee", "Mayflower"},
{"Michigan", "Robin", "Apple Blossom"},
{"Minnesota", "Common Loon", "Pink and White Lady's Slipper"},
{"Mississippi", "Mockingbird", "Magnolia"},
{"Missouri", "Bluebird", "Hawthorn"},
{"Montana", "Western Meadowlark", "Bitterroot"},
{"Nebraska", "Western Meadowlark", "Goldenrod"},
{"Nevada", "Mountain Bluebird", "Sagebrush"},
{"New Hampshire", "Purple Finch", "Purple Lilac"},
{"New Jersey", "Eastern Goldfinch", "Purple Violet"},
{"New Mexico", "Roadrunner", "Yuca Flower"},
{"NewYork", "Bluebird", "Rose"},
{"North Carolina", "Cardinal", "Dogwood"},
{"North Dakota", "Western Meadowlark", "Wild Prairier Rose"},
{"Ohio", "Cardinal", "Scarlet Carnation"},
{"Oklahoma", "Scissor-Tailed Flycatcher", "Mistletoe"},
{"Oregon", "Western Meadowlark", "Oregon Grape"},
{"Pennsylvania", "Ruffed Grouse", "Mountain Laurel"},
{"Rhode Island", "Rhode Island Red", "Violet"},
{"South Carolina", "Carolina Wren", "Yellow Jessamine"},
{"South Dakota", "Ring-Neckked Pheasant", "American Pasqueflower"},
{"Tennessee", "Mockingbird", "Iris"},
{"Texas", "Mockingbird", "Bluebonnet"},
{"Utah", "California Gull", "Sego Lily"},
{"Vermont", "Hermit Thrush", "Red Clover"},
{"Virginia", "Cardinal", "Dogwood"},
{"Washington", "Willow Goldfinch", "Western Rhododendron"},
{"West Virginia", "Cardinal", "Big Rhododendron"},
{"Wisconsin", "Robin", "Wood Violet"},
{"Wyoming", "Meadowlark", "Indian Paintbrush"},
};

while (true) {


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

if (stateName.trim().equalsIgnoreCase("None")) {
System.exit(0);
} else {
int i = getInfo(stateInformation, stateName);
if (i != -1) {
System.out.println("Bird: " + stateInformation[i][1]);
System.out.println("Flower: " + stateInformation[i][2]);
} else {
System.out.println("Not A Valid State");
}
}
}


}
}

====================

For The below countries we should remove space between two string because we are giving inputs from keyboard

java will treat as command line arguments.

For input "New york" it is taking up New only so it is not working if you check other countries it is single string but for the below countries thos are two strings.If you remove space betwenn those two strings you will get output

New Hampshire
New Jersey
New Mexico
North Carolina
North Dakota
Rhode Island
South Carolina
South Dakota
West Virginia

===================

below changes should in the code

NewHampshire
NewJersey
NewMexico
NorthCarolina
NorthDakota
RhodeIsland
SouthCarolina
SouthDakota
WestVirginia

we should remove space between them

then it will work..

Please comment if you having any quiries

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