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

Print person1\'s kids, apply the incNumKids() method, and print again, outputtin

ID: 3662450 • Letter: P

Question

Print person1's kids, apply the incNumKids() method, and print again, outputting text as below. End each line with newline.
Sample output for below program:

// ===== Code from file PersonInfo.java =====
public class PersonInfo {
   private int numKids;

   public void setNumKids(int personsKids) {
      numKids = personsKids;
      return;
   }

   public void incNumKids() {
      numKids = numKids + 1;
      return;
   }

   public int getNumKids() {
      return numKids;
   }
}
// ===== end =====

// ===== Code from file CallPersonInfo.java =====
public class CallPersonInfo {
   public static void main (String [] args) {
      PersonInfo person1 = new PersonInfo();

      person1.setNumKids(3);

      /* Your solution goes here */

      return;
   }
}
// ===== end =====

Explanation / Answer

// ===== Code from file PersonInfo.java =====
public class PersonInfo {
private int numKids;
public void setNumKids(int personsKids) {
numKids = personsKids;
return;
}
public void incNumKids() {
numKids = numKids + 1;
return;
}
public int getNumKids() {
return numKids;
}
}
// ===== end =====
// ===== Code from file CallPersonInfo.java =====
public class CallPersonInfo {
public static void main (String [] args) {
PersonInfo person1 = new PersonInfo();
person1.setNumKids(3);
System.out.println("Kids: "+person1.getNumKids());
person1.incNumKids();
System.out.println("New baby, kids now: "+person1.getNumKids());   
  
return;
}
}
// ===== end =====

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote