NETBEANS- JAVA: WELL DOCUMENTED CODE. The data file statedata.dat in the canvas
ID: 3663827 • Letter: N
Question
NETBEANS- JAVA: WELL DOCUMENTED CODE.
The data file statedata.dat in the canvas files for Week 1 is a plain text file containing three pieces of information for each state in the United States: the name of the state the state capital the population (as of July 2015) each item is on separate line in the file, such as Alabama Montgomery 4858979 Alaska Juneau 738432 Arizona Phoenix 6828065 and so on... Your task, after reading Appendix 8- Software Flexibility, is to create a software package as a Net Beans project that contains three classes: an executable class for the project itself a class of states, with the properties name, capital, and population a class for an array of state objects The state and array classes should contain appropriate properties and methods to work with those properties. Your project's class (with the same name as the package) should contain a main method, and methods to test your other classes as follows: load the data from the data file into the array of states. Print the list of states -- including each state's name, capital and population -- with the data for each state on a separate line. A method that asks the user for the name of a state, then either displays the data for that state, or says the state was not found in the list. The main method should simply call the other methods in the class to show that they work. Each class should be in its own file, within the same package in the same NetBeans project. The end of Appendix B addresses how to do this. The NetBeans project city Project from CSCI 211, shows an example of this. In the project, you can see that each of the classes - City, Vertex, Edge, etc., ... is in its own file within the project. This is included as an example in the files for Week 1. Most of what's in the project is beyond the scope of this course, but it does show you how Java projects should contain separate classes in separate files within the same project. Please ask me if you have any questions or run into any trouble.Explanation / Answer
public class State
{
private String stateName;
private int statePopulation;
private City capital;
private State.City population;
public State(String state, int statepop, String cap, int pop, String city, int citypop)
{
stateName = state;
this.statePopulation = statepop;
City capital = new City(city, citypop);
State.City population = new State.City(cap, pop);
}
public String getStateName()
{
return stateName;
}
public int getStatePopulation()
{
return statePopulation;
}
private class City
{
private String cityName;
private int cityPopulation;
public City(String city, int citypop)
{
cityName = city;
cityPopulation = citypop;
}
public void displayCity()
{
System.out.println("City Name: " + cityName);
System.out.println("City Population: " + cityPopulation);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.