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

Write a Java project with two different classes. First class named Lab10main sho

ID: 3568272 • Letter: W

Question

Write a Java project with two different classes. First class named Lab10main should contain only the main() method and the second class named Lab10 should contain two overloaded predicate methods named isPower(x, y) and isPower(x, y, z)where the first method isPower(x, y) will return true if x is power of y, otherwise false and the second method isPower(x, y, z)will return true if x and y is power of z, otherwise false. These methods should be invoked from the main() method in Lab10main class. Then print out the result value from the main() method in Lab10main class.

Explanation / Answer

class Lab10
{
   public boolean isPower(int x, int y)
   {
       System.out.println(x + " " + y + (x /y));
       if ((x % y) == 0)
           return true;
       else
           return false;
   }

   public boolean isPower(int x, int y, int z)
   {
       if (isPower(x, z) && isPower(y, z))
           return true;
       else
           return false;
   }
}

class Lab10main
{
   public static void main(String args[])
   {
       Lab10 l = new Lab10();
       System.out.println("isPower(4, 2): " + l.isPower(4, 2));
       System.out.println("isPower(3, 2): " + l.isPower(3, 2));
       System.out.println("isPower(8, 4, 2): " + l.isPower(8, 4, 2));
       System.out.println("isPower(7, 4, 2): " + l.isPower(7, 4, 2));
   }
}

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