Created
June 5, 2012 14:08
-
-
Save kaakaa/2875230 to your computer and use it in GitHub Desktop.
みなとRuby会議01 ソーシャルコーディング あみだくじ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.yokohama.rb.kaigi01; | |
import org.yokohama.rb.kaigi01.result.ResultViewModel; | |
public class CreateAmidakuji { | |
public CreateAmidakuji() { | |
ResultViewModel model = new ResultViewModel(5); | |
System.out.println(model.toString()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.yokohama.rb.kaigi01.result; | |
public interface ResultColumn { | |
public String toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.yokohama.rb.kaigi01.result; | |
public class ResultViewHeader implements ResultColumn { | |
private String header = " A B C D E"; | |
public ResultViewHeader(){ | |
} | |
@Override | |
public String toString() { | |
return this.header; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.yokohama.rb.kaigi01.result; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class ResultViewModel { | |
private final int columnNumber = 8; | |
private final int rowNumber; | |
private List<ResultColumn> view; | |
public ResultViewModel(int rowNumber) { | |
this.view = new ArrayList<ResultColumn>();; | |
this.rowNumber = rowNumber; | |
initializeView(); | |
} | |
private void initializeView() { | |
view.add(new ResultViewHeader()); | |
for(int i = 0; i < this.columnNumber-2; i++){ | |
view.add(new ResultViewElement(this.rowNumber)); | |
} | |
view.add(new ResultViewFooter(this.rowNumber)); | |
} | |
public String toString(){ | |
String result = ""; | |
for (ResultColumn column : this.view) { | |
result += column.toString() + "¥n"; | |
} | |
return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.yokohama.rb.kaigi01.result; | |
import java.util.Random; | |
public class ResultViewElement implements ResultColumn { | |
private String column = " "; | |
private int rowNumber; | |
private final String TAB = " "; | |
public ResultViewElement(int rowNumber){ | |
this.rowNumber = rowNumber; | |
this.fill(); | |
} | |
protected void fill() { | |
// 結果を初期化 | |
initializeColumn(); | |
} | |
private int getRandom() { | |
return new Random().nextInt(this.rowNumber-1); | |
} | |
public int getRowNumber() { | |
return rowNumber; | |
} | |
public void setRowNumber(int rowNumber) { | |
this.rowNumber = rowNumber; | |
} | |
public void initializeColumn() { | |
int rnd = getRandom(); | |
for(int i=0; i<rowNumber; i++){ | |
if(i == rnd){ | |
this.column += "|---"; | |
}else{ | |
this.column += "|" + TAB ; | |
} | |
} | |
} | |
@Override | |
public String toString() { | |
return this.column; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment