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

Can someone help me with the two questions in this code (written as comments)? p

ID: 3772234 • Letter: C

Question

Can someone help me with the two questions in this code (written as comments)?

public class Test {
public static void main(String[] args) {

System.out.println(max(1, 2)); }

public static double max(int num1, double num2) {
System.out.println("max(int, double) is invoked"); /* 2.1 what is the pre-condition and the post

condition here */

if (num1 > num2) return num1;

else
return num2;

} /* 2.2 what is the pre-condition and the post condition here */ public static double max(double num1, int num2) {

System.out.println("max(double, int) is invoked");

if (num1 > num2) return num1;

else
return num2;

} }

Explanation / Answer

public class Test
{
   public static void main(String[] args)
   {
       System.out.println(max(1, 2));
   }
   public static double max(int num1, double num2)
   {
       System.out.println("max(int, double) is invoked");
/* 2.1 what is the pre-condition and the post
condition here */
       /* here pre condition is num1 and num2 should have int value stored.*/
       if (num1 > num2) return num1;
       else
       return num2;
       /* depending on values in num1 and num2 the value is returned which is large*/
   } /* 2.2 what is the pre-condition and the post condition here */
/* here num1 and num2 must have double value passed in it*/
   public static double max(double num1, int num2)
   {
       System.out.println("max(double, int) is invoked");
       if (num1 > num2) return num1;
       else
           return num2;

   }
   /* post condition here is that the above method returns large value among two doubles*/
}

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