Question: public class Person { private String name; private int id; private static int personCount = 0; // constructor public Person(String pname) { name = pname;



public class Person { private String name; private int id; private static int personCount = 0; // constructor public Person(String pname) { name = pname; personCount++; id = 100 + personCount; } public String toString() { return "name: " + name (Person count: } + id: " + id + personCount + ")"; 10 // static/class method public static int getCount() { return personCount; } } (a) What is the output of the following code segment? (6 points) Person charles = new Person("Charles Babbage"); System.out.println(Person.getCount()); System.out.println(charles); Person ada = new Person ("Ada Lovelace"); System.out.println(ada.getCount()); Person ed = new Person("Ed Roberts"); System.out.println(Person.getCount()); (b) Add a setter method to this class that will allow the user to reset all instance variables to the values sent in as a parameter. (4 points) 1. Determine whether each of the following is an example of a class method, instance method, class variable, or instance variable. (1 point each) (a) Math.sqrt(64.0) (b) list.length (c) Character.isLowerCase('H') (d) Math.PI (e) name.indexOf("GA") (f) s.length() (a) Using one line of code, declare and initialize an array that will hold five state abbrevi- ations. Those five states should be assigned in your answer. (2 points) [] Staics = { "GA", "FL", "LA" String . 2 NY", "Tx" }; (b) Write a code fragment (not a complete method) to count the strings in your array that would precede "GA" in the dictionary. You must use the compareTo method in your solution. (6 points) (c) Write a complete value-returning class method that will find the maximum string in your array (i.e., the one that would appear last in dictionary order). Your method should have one parameter for the array. (8 points)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
