Question

Needing help compiling this project Write a Java program the displays the State bird and flower....

Needing help compiling this project

Write a Java program the displays the State bird and flower. You should use your IDE for this exercise. You should also use Java classes to their full extent to include multiple methods and at least two classes. 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 “None” is entered. After all States have been entered by the user, the program should display a summary of the results. You will need to do some research to find the State birds and flowers. Here is a sample run: 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 **** Thank you ***** A summary report for each State, Bird, and Flower is: Maryland, Baltimore Oriole, Black-eyed Susan Delaware, Blue Hen Chicken, Peach Blossom Please visit our site again!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code with screenshot.

You need to find out the details for other different states and update the below 2D array, I just added details for maryland and delaware

private static final String[][] stateData = { {"Maryland", "Baltimore Oriole", "Black-eyed Susan"}, {"Delaware", "Blue Hen Chicken", "Peach Blossom"}, {"", "", ""}};

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

package basket;

import java.nio.channels.ScatteringByteChannel;
import java.util.ArrayList;
import java.util.Scanner;

public class StateTreasure {

    private static final String[][] stateData = {
            {"Maryland", "Baltimore Oriole", "Black-eyed Susan"},
            {"Delaware", "Blue Hen Chicken", "Peach Blossom"},
            {"", "", ""}};


    public static void main(String[] args) {
        ArrayList<String> lookupStates = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print("Enter a State or None to exit: ");
            String state = scanner.nextLine();
            int index = getStateIndex(state);
            if (index >= 0) {
                System.out.printf("%-7s%15s%9s%15s\n", "Bird:", stateData[index][1], "Flower:", stateData[index][2]);
                lookupStates.add(state);
            } else if (state.equalsIgnoreCase("NONE")) {
                System.out.println(" **** Thank you ***** A summary report for each State, Bird, and Flower is:");
                for (String states : lookupStates) {
                    int i = getStateIndex(states);
                    System.out.printf("%s, %s, %s\n", stateData[i][0], stateData[i][1], stateData[i][2]);
                }
                break;
            } else {
                System.out.println("Details not available for " + state);
            }
        }

    }


    public static int getStateIndex(String state) {

        for (int i = 0; i < stateData.length; i++) {
            if (stateData[i][0].equalsIgnoreCase(state)) {
                return i;
            }
        }
        return -1;
    }
}

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

Add a comment
Know the answer?
Add Answer to:
Needing help compiling this project Write a Java program the displays the State bird and flower....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java....

    FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java. Include these steps: Write an application that provides the criteria for a strong password, and accepts a user's password from an input dialog box. If the entered password is less than six characters, more than 10 characters, or does not contain at least one uppercase letter and one digit, prompt the user to enter again. When the user's entry meets all the password requirements,...

  • Write an interactive Java program, ColorRange.java, which when given a wavelength in nanometers will return the...

    Write an interactive Java program, ColorRange.java, which when given a wavelength in nanometers will return the corresponding color in the visible spectrum. Color Wavelength (nm) Violet 380-450 Blue 451-495 Green 496-570 Yellow 571-590 Orange 591-620 Red 621-750 Task You must implement the following using a suitable decision statement. 1. Use a GUI prompt for the user to enter the wavelength, the wavelength should be of type double. 2. For each range (e.g. 380-450) the number on the left is included...

  • [JAVA} Thanks in advance for your help! Write a program that asks the user to type...

    [JAVA} Thanks in advance for your help! Write a program that asks the user to type in ages. They will type a negative age when they finish entering the ages. The program will print out the average of all of the ages and the oldest age entered. It should end with a newline. Sample output #1 Type a negative for age to exit Enter your age: 21 Enter your age: 22 Enter your age: 21 Enter your age: -8 The...

  • This is JAVA. Must write a short description of this program, usually a sentence or two...

    This is JAVA. Must write a short description of this program, usually a sentence or two will be sufficient. All the classes, methods and data fields should be clearly documented (commented). Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 4 percent and the county sales tax is 2 percent. The program should display the amount of...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • Project overview: Create a java graphics program that displays an order menu and bill from a...

    Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other establishment you prefer. In this program the design is left up to the programmer however good object oriented design is required. Below are two images that should be used to assist in development of your program. Items are selected on the Order Calculator and the Message window that displays the Subtotal, Tax and Total is displayed when the Calculate...

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

  • Write a java netbeans program. Project Two, Super Bowl A text file named “SuperBowlWinners.txt” contains the...

    Write a java netbeans program. Project Two, Super Bowl A text file named “SuperBowlWinners.txt” contains the names of the teams that won the Super Bowl from 1967 through 2019. Write a program that repeatedly allows a user to enter a team name and then displays the number of times and the years in which that team won the Super Bowl. If the team entered by the user has never won the Super Bowl, report that to the user instead. For...

  • Write a program that will help a student learn multiplication. Use SecureRandom object to produce two...

    Write a program that will help a student learn multiplication. Use SecureRandom object to produce two positive integers between 1 and 20. The program should then prompt the user with a question (use a sentinel-controlled loop), such as: How much is 10 times 11? The student then inputs the answer. If the answer is correct display the message “very good” and ask another question. If the answer is wrong to display the message “no, please try again” and let the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT