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

Code as mentioned in problem: public class TrashAndTakeOut { public static void

ID: 3805654 • Letter: C

Question

Code as mentioned in problem:

public class TrashAndTakeOut

   {

   public static void trash (int x)

   {

int m, n;

m = 0;

if (x > 0)

   m = 4;

if (x > 5)

   n = 3*m;

else

   n = 4*m;

int o = takeOut (m, n);

System.out.println ("o is: " + o);

   }

   public static int takeOut (int a, int b)

   {

int d, e;

d = 42*a;

if (a > 0)

   e = 2*b+d;

else

   e = b+d;

return (e);

   }

   public static void main (String []argv)

   { // Driver method for trashAndTakeOut

// Read an integer from standard input, call trashAndTakeOut()

if (argv.length != 1)

{

   System.out.println ("Usage: java TrashAndTakeOut v1");

   return;

}

int x = 0;

try

{

   x = Integer.parseInt (argv[0]);

}

catch (NumberFormatException e)

{

   System.out.println ("Entry must be an integer, using 1.");

   x = 1;

}

trash (x);

   }

}

Question 3 (12 points) Use the following methods trash() and takeout() to answer questions a-c. You can find the code on Canvas. 1 public void trash (int x) 15 public int takeout int a, int b) 2 16 int m n; 17 int d, e 18 m 0; 19 d 42 a 6 if (x 0) 20 if (a 0) m 4 e 2 b+d 21 if (x 5) 22 else e b+d 23 n 3*m; 24 return (e) 10 else 25 4 m 12 int o takeouts (m n) 13 System.out.println ("o is: o) 14 a) Give all call sites using the line numbers given. (2 points) b) Give all pairs of last-defs and first-uses. (4 points) c) Provide test inputs thatsatisfy all-coupling-uses (note that trash() only has one input). (6 points)

Explanation / Answer

a) call sites : function calling line

in method trash

line 12 :calling function takeOut

line 13: calling standard output method

b)

last-def is the definition that goes through function call

first-use picks up that definition

last-defs are : lines : 5,7,9,11

first-use are : 19,21,23,24,12

c)

test case1: x=0; m=0,n=0;

test case2: x=1; m=4,n=16;

test case3:-x=6;m=4,n=12;

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