Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting methods and constructors
    primarykey
    data
    text
    <p>OK, i need someone to explain to me where to start on this project.</p> <p>First I need to overload the constructor by adding a default (no-args) constructor to <em>Person</em> that defines an object to have the name "N/A" and an id of -1. </p> <p>Then i need to add a setter method named reset that can be used to reset the two private instance variables of this class to two values passed in as parameters. </p> <p>Then I need to add a getter method named getName and getId that can be used to retrieve these two private variables</p> <p>Here is the code:</p> <pre><code>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 + " id: " + id + " (Person count: " + personCount + ")"; } // static/class method public static int getCount() { return personCount; } </code></pre> <p>////////////////////////////////////////////////</p> <pre><code>public class StaticTest { public static void main(String args[]) { Person tom = new Person("Tom Jones"); System.out.println("Person.getCount(): " + Person.getCount()); System.out.println(tom); System.out.println(); Person sue = new Person("Susan Top"); System.out.println("Person.getCount(): " + Person.getCount()); System.out.println(sue); System.out.println("sue.getCount(): " + sue.getCount()); System.out.println(); Person fred = new Person("Fred Shoe"); System.out.println("Person.getCount(): " + Person.getCount()); System.out.println(fred); System.out.println(); System.out.println("tom.getCount(): " + tom.getCount()); System.out.println("sue.getCount(): " + sue.getCount()); System.out.println("fred.getCount(): " + fred.getCount()); } } </code></pre> <p>I'm not exactly sure where to start and I don't want just the answer. I'm looking for someone to explain this clearly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload