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

The code below shows some of the text for a class called City. Now write a compl

ID: 3681101 • Letter: T

Question

The code below shows some of the text for a class called City. Now write a complete public constructor, which takes a String parameter called cityName. Your code should initialize the name attribute of the City class to the value of cityName. It should initialize the population attribute to a value of -1. (Presumably the class has a setPopulation method that will be used to set the city's population after the object has been constructed).

public class City {

  private String name;
  private int population;

Explanation / Answer

//declaration of class

public class City{

/.declaring variables

private String name;

private int population;

//public constructor with string parameter called cityName

public City(String cityName)

{

//initializing name and population variables

name = cityName;

population = -1;

}