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

Reading and drawing object diagrams is one skill you will be developing this wee

ID: 3826526 • Letter: R

Question

Reading and drawing object diagrams is one skill you will be developing this week. This exercise is designed to help you understand how they work. This is designed as a collaborative exercise.

Examine the object diagram shown at right. If this diagram represents the state of memory before the following statements are executed, what are the values of x and y after the statements are executed? How is the object diagram changed by these statements?

fred.deposit( 150 );
double x = barney.getBalance();
double y = fred.getBalance();

fred barney String BankAccount Flintstone Owner String acctID "12345M" balance 625 String BankAccount owner a Rubble acctID String balance 1000 08964G

Explanation / Answer

Two objects fred and barney are linked with the two Bank accounts flintstone and Rubble.
fred.deposit( 150 );
//when we run this statement it adds the money to the flintstone bank account
so from the object diagram, we can see balance = 625
now new balance = 625+150
               = 775
              
double x = barney.getBalance(); It returns the balance of rubble account so x = 1000

double y = fred.getBalance(); It returns the updated balance of flintstone so y =775