Object Diagram Exercise 1) What will the object diagram look like after executio
ID: 3831439 • Letter: O
Question
Object Diagram Exercise
1) What will the object diagram look like after execution of the client code?
2) What will be displayed by this client code?
Supplier Code
Client Code
public class Sample{
private int alpha, beta;
public Sample( ) {
alpha = -1;
beta = 3;
}
public int scramble( int q ){
return alpha + beta - q ;
}
public void modify(){
int temp = alpha;
alpha = beta;
beta = 2 * temp;
}
public void increase( int delta){
alpha = alpha + delta;
beta = beta + delta;
}
public void display(){
System.out.println( alpha );
System.out.println( beta );
}
}
Sample s = new Sample( );
Sample t = new Sample( );
s.modify( );
t.increase(3);
s.display( );
t.display( );
int x = s.scramble( 2 );
s.increase( x );
s.display( );
t.increase ( s.scramble( -2 ) );
t.display( );
Supplier Code
Client Code
public class Sample{
private int alpha, beta;
public Sample( ) {
alpha = -1;
beta = 3;
}
public int scramble( int q ){
return alpha + beta - q ;
}
public void modify(){
int temp = alpha;
alpha = beta;
beta = 2 * temp;
}
public void increase( int delta){
alpha = alpha + delta;
beta = beta + delta;
}
public void display(){
System.out.println( alpha );
System.out.println( beta );
}
}
Sample s = new Sample( );
Sample t = new Sample( );
s.modify( );
t.increase(3);
s.display( );
t.display( );
int x = s.scramble( 2 );
s.increase( x );
s.display( );
t.increase ( s.scramble( -2 ) );
t.display( );
Explanation / Answer
After execution of Client code, state of each object is:
s:Sample
- alpha : 2
- beta : -1
t:Sample
- alpha : 3
- beta : 7
Output:
3
-2
2
6
2
-3
3
7
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.