Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

above the line is first file, below is second. code is already completed i just need the memory diagram. MyInteger.java public class MyInteger { int

above the line is first file, below is second. code is already completed i just need the memory diagram.

MyInteger.java

public class MyInteger { int value; MyInteger(int value){ this.value = value; } public int getValue(){ return value; } public void setValue(int value) { this.value = value; } }

------------------------------------------------------------------------------------------------------

Test.java

class Test { //CASE 1 static void swap(MyInteger a, MyInteger b) { //INSERT YOUR CODE HERE - CASE 1 int tmp; tmp = a.getValue(); a.setValue(b.getValue()); b.setValue(tmp); } //CASE 2 static void swap(Integer a, Integer b) { //INSERT YOUR CODE HERE - CASE 2 Integer tmp = a; a = b; b = tmp; } //CASE 3 static void swap(int a, int b) { //INSERT YOUR CODE HERE - CASE 3 int tmp = a; a = b; b = tmp; } //CASE 4 static void swap(int [] arr ) { //INSERT YOUR CODE HERE - CASE 4 int tmp; tmp = arr[0]; arr[0] = arr[1]; arr[1] = tmp;

} static void printHeader( int caseID ) { System.out.println(" ....................................................."); System.out.println("........................CASE " +caseID+"......................."); System.out.println("....................................................."); } public static void main( String [] args ) { //CASE 1 MyInteger a, b; a = new MyInteger(5); b = new MyInteger(10); printHeader(1); System.out.println("Before: a = " + a.getValue() + " and b = "+ b.getValue()); swap(a, b); System.out.println("After: a = " + a.getValue() + " and b = "+ b.getValue()); //CASE 2 Integer c, d; c = new Integer(5); d = new Integer(10); printHeader(2); System.out.println("Before: c = " + c + " and b = "+ d ); swap(c, d); System.out.println("After: c = " + c + " and b = "+ d ); //CASE 3 int e, f; e = 5; f = 10; printHeader(3); System.out.println("Before: e = " + e + " and f = "+ f ); swap(e, f); System.out.println("After: e = " + e + " and f = "+ f ); //CASE 4 int[] arr; arr = new int[2]; arr[0] = 5; arr[1] = 10; printHeader(4); System.out.println("Before: arr[0] = " + arr[0] + " and arr[1] = "+ arr[1] ); swap(arr); System.out.println("After: arr[0] = " + arr[0] + " and arr[1] = "+ arr[1] ); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago