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

\"Parameters and Overloaded Methods\" Please respond to the following: Imagine t

ID: 639115 • Letter: #

Question

"Parameters and Overloaded Methods"  Please respond to the following:

Imagine that you are creating a program for calculating an average of either two (2) or three (3) numbers. Determine the manner in which the overloaded methods can be used to solve this. Include one (1) example of a scenario or situation to support your response.

Discuss the purpose of having a constructor with a parameter. Compare and contrast the functionality between a constructor with a parameter and a constructor without a parameter. Provide one (1) example of each constructor in question to support your answer.

Explanation / Answer

/*"Parameters and Overloaded Methods" Please respond to the following:

Imagine that you are creating a program for calculating an average of either two (2) or three (3) numbers. Determine the manner in which the overloaded methods can be used to solve this. Include one (1) example of a scenario or situation to support your response.

Discuss the purpose of having a constructor with a parameter. Compare and contrast the functionality between a constructor with a parameter and a constructor without a parameter. Provide one (1) example of each constructor in question to support your answer.*/


public class OverloadDemo
{
   private int n1,n2,n3;
   OverloadDemo()
   {
   }

   OverloadDemo(int a,int b)
   {
       n1=a;
       n2=b;
   }
   OverloadDemo(int a,int b,int c)
   {
       n1=a;
       n2=b;
       n3=c;
   }


   float average(int a,int b)
   {
       float av;
       av=(float)(a+b)/2;
       return av;
   }
   float average(int a,int b,int c)
   {
           float av;
           av=(float)(a+b+c)/3;
           return av;
   }


   public static void main(String args[])
   {
       OverloadDemo ob=new OverloadDemo(1,3);
       float a=ob.average(1,3);
       System.out.println("average="+a);
       OverloadDemo ob1=new OverloadDemo(1,3,5);
       float b=ob1.average(1,3,5);
       System.out.println("average="+b);

   }
}