Memento Lab 1
Given the following code:
DocumentMemento.java
package MementoLabOne;
public class DocumentMemento {
private final String content;
private final String fontName;
private final int fontSize;
public DocumentMemento(String content, String fontName, int fontSize) {
this.content = content;
this.fontName = fontName;
this.fontSize = fontSize;
}
public String getContent() {
return content;
}
public String getFontName() {
return fontName;
}
public int getFontSize() {
return fontSize;
}
}
History.java
package MementoLabOne;
import java.util.ArrayDeque;
import java.util.Deque;
public class History {
private Deque<DocumentMemento> mementos = new ArrayDeque<>();
public void push(DocumentMemento memento) {
mementos.push(memento);
}
public DocumentMemento pop() {
return mementos.pop();
}
}
Document.java
package MementoLabOne;
public class Document {
private String content;
private String fontName;
private int fontSize;
public DocumentMemento createMemento() {
return new DocumentMemento(content, fontName, fontSize);
}
public void restore(DocumentMemento memento) {
this.content = memento.getContent();
this.fontName = memento.getFontName();
this.fontSize = memento.getFontSize();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getFontName() {
return fontName;
}
public void setFontName(String fontName) {
this.fontName = fontName;
}
public int getFontSize() {
return fontSize;
}
public void setFontSize(int fontSize) {
this.fontSize = fontSize;
}
@Override
public String toString() {
return "Document{" +
"content='" + content + '\'' +
", fontName='" + fontName + '\'' +
", fontSize=" + fontSize +
'}';
}
}
Complete the following driver by accomplishing the TO-DOs
The output should look like the following: