Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class MyLEDMatrix {
- MyLEDLamp[][] ledmatrix;
- public MyLEDMatrix(int n){
- this.ledmatrix = new MyLEDLamp[n][n];
- int panjang = this.ledmatrix.length;
- int lebar = this.ledmatrix[0].length;
- for(int i = 0;i<panjang;i++){
- for(int j = 0;j<lebar;j++){
- this.ledmatrix[i][j]=new MyLEDLamp();
- }
- }
- }
- public void setAll(boolean on){
- int panjang = this.ledmatrix.length;
- int lebar = this.ledmatrix[0].length;
- for(int i = 0;i<panjang;i++){
- for(int j = 0;j<lebar;j++){
- if(on == true){
- this.ledmatrix[i][j].setOn();}
- else{
- this.ledmatrix[i][j].setOff();
- }
- }
- }
- }
- public String print(){
- int panjang = this.ledmatrix.length;
- int lebar = this.ledmatrix[0].length;
- String output = "";
- for(int i = 0;i<panjang;i++){
- for(int j = 0;j<lebar;j++){
- if(this.ledmatrix[i][j].getStatus() == true){
- output += "@";}
- else{
- output += " ";}
- }
- output += "\n";
- }
- return output;
- }
- public void setTop(){
- String res = new String();
- int panjang = this.ledmatrix.length;
- int lebar = this.ledmatrix[0].length;
- for(int k = 0;k <= (panjang/2);k++){
- int l;
- int x;
- int y;
- for(l = 0;l<(lebar/2)-k;l++){
- this.ledmatrix[k][l].setOff();
- res=res+this.ledmatrix[k][l].print();
- }
- for(x = l;x<=(lebar/2)+k;x++){
- this.ledmatrix[k][l].setOn();
- res=res+this.ledmatrix[k][l].print();
- }
- for(y = x;y<(lebar/2);y++){
- this.ledmatrix[k][l].setOff();
- res=res+this.ledmatrix[k][l].print();
- }
- res=res+"\n";
- }
- System.out.println(res);
- }
- public void setBottom(){
- int panjang = this.ledmatrix.length;
- int lebar = this.ledmatrix[0].length;
- String res = new String();
- for(int k = (panjang/2)+1;k < panjang;k++){
- int l;
- int i;
- for(l = 0;l<lebar;l++){
- this.ledmatrix[k][l].setOff();
- res=res+this.ledmatrix[k][l].print();
- }
- res=res+"\n";
- }
- for(int i = (panjang/2)+1;i<panjang;i++){
- this.ledmatrix[i][(lebar/2)].setOn();
- res=res+this.ledmatrix[i][l].print();
- }
- }
- public void setArrow(){
- this.setTop();
- this.setBottom();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement