U.S. States Create a class State with five properties to hold the information ab
ID: 3123540 • Letter: U
Question
U.S. States Create a class State with five properties to hold the information about a single state and a method that calculates the density (people per square mile) of the state. (Schneider 577) Schneider, David I. Introduction to Programming Using Visual Basic, 10th Edition. Pearson, 20160620. VitalBook file. I need the instruction like Objective, Property and settings thanks
Explanation / Answer
class Country { String name; long population; double area; Country(String name, long population, double area) { this.name = name; this.population = population; this.area = area; } double density () { if (area > 0) return population/area; else return 0; } public static void main(String[] args) { int numberOfCountries = 10; Country[] countries = new Country[numberOfCountries]; double lArea = -1; int lAreaIndex = -1; long lPop = -1; int lPopIndex = -1; double lDensity = -1; int lDensityIndex = -1; for (int i=0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.