Hello. I have found java code that I am trying to compile and get
Hello. I have found java code that I am trying to compile and get
to run, however it is giving me the error “No main class found”. I know I need to include a main class, but I do not know where. Can anyone help?
I am copy/paste my code below:
package stateinfo;
import java.util.Scanner;
/**
*File: StateInfo.java
*Author: XXXXXXXXXXXX
*Date: 25 Feb 2018
*Purpose: Provide state flower and bird when user gives state
*/
public class StateInfo{
//Array of all state flowers and bird
public String[][] states = {
{“Alabama”, “Yellowhammer”, “Camelia”},
{“Alaska”, “Willow Ptarmigan”, “Forget-Me-Not”},
{“Arizona”, “Cactus Wren”, “Saguaro Cactus Blossom”},
{“Arkansas”, “Mockingbird”, “Apple Blossom”},
{“California”, “California Valley Quail”, “Golden Poppy”},
{“Colorado”, “Lark Bunting”, “Rocky Mountain Columbine”},
{“Connecticut”, “Robin”, “Mountain Laurel”},
{“Delaware”, “Blue Hen Chicken”, “Peach Blossom”},
{“Florida”, “Mockingbird”, “Orange Blossom”},
{“Georgia”, “Brown Thrasher”, “Cherokee Rose”},
{“Hawaii”, “Nene”, “Hawaiian Hibiscus”},
{“Idaho”, “Mountain Bluebird”, “Syringa, mock orange”},
{“Illinois”, “Cardinal”, “Violet”},
{“Indiana”, “Cardinal”, “Peony”},
{“Iowa”, “Eastern Goldfinch”, “Wild Praire Rose”},
{“Kansas”, “Western Meadowlark”, “Sunflower”},
{“Kentucky”, “Cardinal”, “Goldenrod”},
{“Louisiana”, “Eastern Brown Pelican”, “Magnolia”},
{“Maine”, “Chickadee”, “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 Slippper”},
{“Mississippi”, “Mockingbird”, “Magnolia”},
{“Missouri”, “Bluebird”, “Hawthorn”},
{“Montana”, “Western Meadowlark”, “Bitterroot”},
{“Nebraska”, “Western Meadowlark”, “Goldenrod”},
{“Nevada”, “Mountain Bluebird”, “Sagebrush”},
{“NewHampshire”, “Purple Finch”, “Purple Lilac”},
{“NewJersey”, “Eastern Goldfinch”, “Violet”},
{“NewMexico”, “Roadrunner”, “Yucca Flower”},
{“NewYork”, “Bluebird”, “Rose”},
{“NorthCarolina”, “Cardinal”, “Flowering Dogwood”},
{“NorthDakota”, “Western Meadowlark”, “Wild Praire Rose”},
{“Ohio”, “Cardinal”, “Scarlet Carnation”},
{“Oklahoma”,”Scissor-tailed Flycatcher”,”Oklahoma Rose”},
{“Oregon”, “Western Meadowlark”, “Oregon Grape”},
{“Pennsylvania”, “Ruffed Grouse”, “Mountain Laurel”},
{“RhodeIsland”, “Rhode Island Red”, “Violet”},
{“SouthCarolina”, “Great Carolina Wren”, “Yellow Jessamine”},
{“SouthDakota”, “Ring-necked Pheasant”, “Pasque Flower”},
{“Tennessee”, “Mockingbird”, “Purple Passionflower”},
{“Texas”, “Mockingbird”, “Bluebonnet Sp.”},
{“Utah”, “Common American Gull”, “Sego Lily”},
{“Vermont”, “Hermit Thrush”, “Red Clover”},
{“Virginia”,”Cardinal”,” American Dogwood”},
{“Washington”, “Willow Goldfinch”, “Coast Rhododendrum”},
{“WestVirginia”, “Cardinal”, “Rhododendron”},
{“Wisconsin”, “Robin”, “Wood Violet”},
{“Wyoming”, “Western Meadowlark”, “Indian Paintbrush”}
}; //End states Array
StringBuilder summary = new StringBuilder(); //new string builder for all information
//Method to find the location of the state
public int findState(String states[][], String state) {
int position = -1;
boolean found = false;
for (int index = 0; index < states.length && !found; index++) {
if(states[index][0].equalsIgnoreCase(state))
position = index;
}
summary = summary.append(state).append(“,”);
return position;
}
//Method to get get use user input and print the information
public void useInfo(){
while(true) {
Scanner userIn = new Scanner(System.in);
System.out.println(“Enter a State or None to exit:”);
String state = userIn.nextLine();
state = state.replaceAll(“\\s”,””);
state = state.substring(0, 1).toUpperCase() + state.substring(1);
if(state.equalsIgnoreCase(“None”)) {
break;
}
else {
int position = findState(states, state);
if(position != -1) {
System.out.println(“Bird: ” + states[position][1]);
summary.append(states[position][1]).append(“,”);
System.out.println(“Flower: ” + states[position][2]);
summary.append(states[position][2]).append(“\n”);
}
}
}
}
//method to print the summary
public void getSummary(){
System.out.println(“Thank you, \nHere is a summary of the information gathered”);
System.out.println(summary);
}