forked from hazukac/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStringDisplay.java
More file actions
30 lines (27 loc) · 804 Bytes
/
StringDisplay.java
File metadata and controls
30 lines (27 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class StringDisplay extends AbstractDisplay {
private String string;
private int width;
private String separator = "|";
private String lineSeparator = "+";
private String lineContent = "-";
public StringDisplay(String string) {
this.string = string;
this.width = string.getBytes().length;
}
public void open() {
this.printLine();
}
public void print() {
System.out.println(this.separator + this.string + this.separator);
}
public void close() {
this.printLine();
}
private void printLine() {
System.out.print(this.lineSeparator);
for (int i = 0; i < this.width; i++) {
System.out.print(this.lineContent);
}
System.out.println(this.lineSeparator);
}
}