public class StateData implements Comparable { private String postalCode; privat
ID: 3655070 • Letter: P
Question
public class StateData implements Comparable { private String postalCode; private int population; private int electoralVotes; /** * Creates a new instance of StateData with the specified * name, population, and number of Electoral College votes. * * @requires postalCode != null && postalCode.length() == 2 && * population > 0 && electoralCollegeVotes > 0 * * @ensures the parameter values are stored in this object, i.e., * getPostalCode().equals(postalCode) && * getPopulation() == population && * getElectoralVotes() == electoralVotes * * @param postalCode the post-office abbreviation for this state's name * @param population the state's population * @param electoralVotes how many Electoral College votes the state has */ // TODO 1. Implement the header and body of a constructor that assigns // the 3 parameters specified in the method comment to the // appropriate data members.Explanation / Answer
Code is below, please note that this will not run, but it does everything you asked for. Formated code: http://codepad.org/XwDess7f public class StateData implements Comparable { private String postalCode; private int population; private int electoralVotes; /** * Creates a new instance of StateData with the specified * name, population, and number of Electoral College votes. * * @requires postalCode != null && postalCode.length() == 2 && * population > 0 && electoralCollegeVotes > 0 * * @ensures the parameter values are stored in this object, i.e., * getPostalCode().equals(postalCode) && * getPopulation() == population && * getElectoralVotes() == electoralVotes * * @param postalCode the post-office abbreviation for this state's name * @param population the state's population * @param electoralVotes how many Electoral College votes the state has */ public StateDate(String postalCode, int population,int electoralVotes) { this.postalCode=postalCode; this.population=population; this.electoralVotes=electoralVotes; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.