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

3. Choose one method from the MonetaryCoin class and give one paragraph of descr

ID: 3848849 • Letter: 3

Question

3. Choose one method from the MonetaryCoin class and give one paragraph of description in the space below. You can focus on one or two of the following areas: 1) functional perspective such as what the method will do; or 2) implementation perspective such as whether the method is polymorphic, or overloaded, etc.

public class MonetaryCoin extends Coin {
   private int value;
   public MonetaryCoin(){
   value = 0;
   }
   public MonetaryCoin(int aValue){
   value = aValue;
   }
   public int getValue(){
   return value;
   }
  
   public String toString(){
   String faceName;
   if (isHeads()) {
   faceName = "head";
   } else {
   faceName = "tail";
   }
   return "The coin has "+faceName+" and value is "+value+".";
   }
}

Explanation / Answer

Considering the method MonetaryCoin(int aValue), we can see that it is an overloaded method. Whenever an object is created for MonetaryCoin class, then the previous function MonetaryCoin() is called by default so as to initialise the private variable with 0 value but in case the private variable is to be initialised with another value then that value will have to be passed as an argument while calling the function MonetaryCoin(int aValue),for example object1.MonetaryCoin(40);

then the private variable will be initialised by 40 as the function MonetaryCoin(int aValue) will be called as it matches the definition of function with an argument.

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