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

Define the missing method. Use \"this\" to distinguish the local member from the

ID: 3662452 • Letter: D

Question

Define the missing method. Use "this" to distinguish the local member from the parameter name.

// ===== Code from file CablePlan.java =====
public class CablePlan {
   private int numDays;

   // FIXME: Define setNumDays() method, using "this" implicit parameter.
   public void setNumDays(int numDays) {

      /* Your solution goes here */

      return;
   }

   public int getNumDays() {
      return numDays;
   }
}
// ===== end =====

// ===== Code from file CallCablePlan.java =====
public class CallCablePlan {
   public static void main (String [] args) {
      CablePlan house1Plan = new CablePlan();

      house1Plan.setNumDays(30);
      System.out.println(house1Plan.getNumDays());

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

Explanation / Answer

public class CablePlan {
   private int numDays;
   // FIXME: Define setNumDays() method, using "this" implicit parameter.
   public void setNumDays(int numDays) {
   /* Your solution goes here */
       this.numDays=numDays;
         
   return;
   }
   public int getNumDays() {
   return numDays;
   }
}


public class CallCablePlan {
public static void main (String [] args) {
CablePlan house1Plan = new CablePlan();
house1Plan.setNumDays(30);
System.out.println(house1Plan.getNumDays());
return;
}
}

OUTPUT:30

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