Information

Deadline No deadline
Submission limit No limitation

Sign in

[Part3] State Managers


Question 1:
StateManager sm;

StateInt a = sm.makeStateInt(6);
StateInt b = sm.makeStateInt(12);

sm.saveState();

a.setValue(6);

sm.saveState();

a.setValue(6);
a.setValue(8);

sm.saveState();
sm.restoreState();
System.out.println(a.value());
a.setValue(5);
System.out.println(a.value());
sm.restoreState();
sm.restoreState();

What is printed?

Question 2:
StateManager sm = new Trailer();

StateInt a = sm.makeStateInt(6);
StateInt b = sm.makeStateInt(12);

sm.saveState();

a.setValue(6);

sm.saveState();

a.setValue(6);
a.setValue(8);

sm.saveState();
sm.restoreState();
System.out.println(a.value());
a.setValue(5);
System.out.println(a.value());
sm.restoreState();
sm.restoreState();

How many objects of type StateEntry are created overall when executing this program?

Question 3:
StateManager sm = new Copier();

StateInt a = sm.makeStateInt(6);
StateInt b = sm.makeStateInt(12);

sm.saveState();

a.setValue(6);

sm.saveState();

StateInt c = sm.makeStateInt(9);

a.setValue(6);
a.setValue(8);

sm.saveState();
sm.restoreState();
System.out.println(a.value());
a.setValue(5);
System.out.println(a.value());
sm.restoreState();
sm.restoreState();

How many objects of type StateEntry are created overall when executing this program?