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

Now that we have two interfaces implemented we should test them. Create a driver

ID: 3763860 • Letter: N

Question

Now that we have two interfaces implemented we should test them. Create a driver file called GettingSumImplements.java. Create an instance of ImplementingSum.java. Then call five sum methods with different parameter types and five multiply methods with different parameter types.

Below is the code I already have!

class ZeroSum
{
   public int sum(int a,int b)
   {
       return 0;
   }
   public int sum(int a,int b,int c)
   {
       return 0;
   }
   public double sum(int a,short c, double b)
   {
       return 0;
   }
   public double sum(double a,int b,short c)
   {
       return 0;
   }
}

// RealSum Class is extending the ZeroSum Class methods and overriding in RealSum Class
class RealSum extends ZeroSum
{
   public int sum(int a,int b)
   {
       return a+b;
   }
   public int sum(int a,int b,int c)
   {
       return a+b+c;
   }

   public double sum(int a,short c, double b)
   {
       return a+b+c;
   }
   public double sum(double a,int b,short c)
   {
       return a+b+c;
   }
}

// Driver Class Called DrivingSum will have the main methods to handle the methods
// of RealSum class
public class DrivingSum {

         public static void main(String[] args) {
                  int x = 10;
                  int y = 20;
                  // x + y = 30....yay?

                  ZeroSum zero= new ZeroSum();
                  RealSum real= new RealSum();                

                  System.out.println("Calling ZeroSum " + zero.sum(x, y) );
                  System.out.println("Calling RealSum " + real.sum(x, y) );

         }

}

public interface InterSum{

public int sum(int a,int b);
   public int sum(int a,int b,int c);
   public double sum(int a,short c, double b);
   public double sum(double a,int b,short c);

}

public int multiply(int a,int b);
   public int multiply(int a,int b,int c);
   public double multiply(int a,short c, double b);
   public double multiply(double a,int b,short c);

}

Explanation / Answer


GettingSumImplements.java. Create an instance of ImplementingSum.java. Then call five sum methods with different parameter types and five multiply methods with different parameter types.

Below is the code I already have!
class ZeroSum
{
   public int sum(int a,int b)
   {
       return 0;
   }
   public int sum(int a,int b,int c)
   {
       return 0;
   }
   public double sum(int a,short c, double b)
   {
       return 0;
   }
   public double sum(double a,int b,short c)
   {
       return 0;
   }
}

// RealSum Class is extending the ZeroSum Class methods and overriding in RealSum Class
class RealSum extends ZeroSum
{
   public int sum(int a,int b)
   {
       return a+b;
   }
   public int sum(int a,int b,int c)
   {
       return a+b+c;
   }

   public double sum(int a,short c, double b)
   {
       return a+b+c;
   }
   public double sum(double a,int b,short c)
   {
       return a+b+c;
   }
}

// Driver Class Called DrivingSum will have the main methods to handle the methods
// of RealSum class
public class DrivingSum {

         public static void main(String[] args) {
                  int x = 10;
                  int y = 20;
                  int a=15;
                  int b =25;
                  int c= 35;
                
                  ZeroSum zero= new ZeroSum();
                  RealSum real= new RealSum();              

              System.out.println("Calling ZeroSum " + zero.sum(x, y) );
              System.out.println("Calling RealSum " + real.sum(x, y) );

         }

}

public interface InterSum{

   public int sum(int a,int b);
   public int sum(int a,int b,int c);
   public double sum(int a,short c, double b);
   public double sum(double a,int b,short c);

}

public interface Multiply {

   public int multiply(int a,int b);
   public int multiply(int a,int b,int c);
   public double multiply(int a,short c, double b);
   public double multiply(double a,int b,short c);

}

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