File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed
Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,14 @@ public class CharDisplay extends AbstractDisplay {
22 private char ch ;
33 private String head = "<<" ;
44 private String tail = ">>" ;
5+
56 public CharDisplay (char ch ) {
67 this .ch = ch ;
78 }
9+ public CharDisplay (String s ) {
10+ // だめ this.ch = s.getBytes()[0];
11+ this .ch = s .charAt (0 );
12+ }
813 public void open () {
914 System .out .print (this .head );
1015 }
Original file line number Diff line number Diff line change 11public class Main {
22 public static void main (String [] args ) {
3- AbstractDisplay d1 = new CharDisplay ('A' );
3+ AbstractDisplay d0 = new CharDisplay ('B' );
4+ AbstractDisplay d1 = new CharDisplay ("A" );
45 AbstractDisplay d2 = new StringDisplay ("Hello, World!!" );
56 AbstractDisplay d3 = new StringDisplay ("Hoge Fuga Piyo" );
67
8+ d0 .display ();
79 d1 .display ();
810 d2 .display ();
911 d3 .display ();
1012 }
11- }
13+ }
14+ /*
15+ open - process - close
16+ */
17+ /*
18+ イベントサイトのレスポンスが違う
19+ class Crawler {
20+ abstract url: sring;
21+ crawl() {
22+ c := this.getContent();
23+ r := this.parse(c);
24+ s := this.close();
25+ }
26+ getContet() {
27+ return http.Get(this.url);
28+ }
29+ }
30+ class AsahiBeerCrawler extends Crawler {
31+ constructor() {
32+ this.url = "http://asahi.com/campaign";
33+ }
34+ parse(c http.Response) {
35+ // アサヒビールのページのHTMLをパースする具体的な処理
36+ }
37+ close() {
38+ // アサヒビールのページのリクエストをクロースずる処理
39+ }
40+ }
41+ class KirinBeerCrawler extends Crawler {
42+ constructor() {
43+ this.url = "http://kirin.com/?view=campaign";
44+ }
45+ }
46+ */
Original file line number Diff line number Diff line change @@ -4,10 +4,12 @@ public class StringDisplay extends AbstractDisplay {
44 private String separator = "|" ;
55 private String lineSeparator = "+" ;
66 private String lineContent = "-" ;
7+
78 public StringDisplay (String string ) {
89 this .string = string ;
910 this .width = string .getBytes ().length ;
1011 }
12+
1113 public void open () {
1214 this .printLine ();
1315 }
@@ -17,6 +19,7 @@ public void print() {
1719 public void close () {
1820 this .printLine ();
1921 }
22+
2023 private void printLine () {
2124 System .out .print (this .lineSeparator );
2225 for (int i = 0 ; i < this .width ; i ++) {
You can’t perform that action at this time.
0 commit comments