U E D R , A S I H C RSS

Java Study2003/두번째과제/곽세환

Board.java

~cpp 
import javax.swing.JOptionPane;

public class Board {
	private int array[][]; // 
	private int max_x;	   // 기
	private int max_y;	   // 기
	
	// 
	public Board(int x, int y) {
		max_x = x;
		max_y = y;
		array = new int[max_y][max_x];
		for (int i = 0; i < max_y; i++)
			for (int j = 0; j < max_x; j++)
				array[i][j] = 0;
	}
	
	//  ?
	public boolean IsStepFull() {
		for (int i = 0; i < max_y; i++)
			for (int j = 0; j < max_x; j++)
				if (array[i][j] == 0)
					return false;
		return true;
	}
	
	//  ?
	public boolean IsPostionWall(int x, int y) {
		if (x == -1 || x == max_x || y == -1 || y == max_y)
			return true;
		else
			return false;
		
	}
	
	// 
	public void PutStep(int x, int y) {
		array[y][x]++;
		
		//    
		//ShowStep();
	}
	
	// 
	public void ShowStep() {
		String output = "";
		for (int i = 0; i < max_y; i++)
		{
			for (int j = 0; j < max_x; j++)
				output += array[i][j] + "    ";
			output += '\n';
		}
		JOptionPane.showMessageDialog(null, output);
	}
}

Roach.java

~cpp 
public class Roach {
	private int p_x; //   x 
	private int p_y; //   y 

	// 
	public void Move(Board bo, int x, int y) {
		p_x = x;
		p_y = y;
		bo.PutStep(p_x, p_y);		

		while (!bo.IsStepFull()) {
			int c_x; //   x 	
			int c_y; //   y 
			do
			{
				c_x = p_x; 
				c_y = p_y; 			 
				int dir = (int)(Math.random() * 8);
				switch (dir)
				{
					case 0: 
							c_y--; 
							break; 
					case 1: 
							c_x++; 
							c_y--; 
							break; 
					case 2: 
							c_x++; 
							break; 
					case 3: 
							c_x++; 
							c_y++; 
							break; 						
					case 4: 
							c_y++; 
							break; 
					case 5: 
							c_x--; 
							c_y++; 
							break; 						
					case 6: 
							c_x--; 
							break; 						
					case 7: 
							c_x--; 
							c_y--; 
							break; 
				}
			} while (!SeeNextPos(bo, c_x, c_y));
			p_x = c_x;
			p_y = c_y;
			bo.PutStep(p_x, p_y);
		}
	}
	
	//  
	// false   true
	public boolean SeeNextPos(Board bo, int x, int y) {
		if (bo.IsPostionWall(x, y))
			return false;
		else
			return true;
	}
}

Human.java

~cpp 
import javax.swing.JOptionPane;

public class Human {
	//  
	public void PutRoach (Roach ro, Board bo, int x, int y) {
		ro.Move(bo, x, y);
	}
	
	// KillRoach 까???
	public void KillRoach (Roach ro) {
		//  ^^
	}
	
	//  
	public void SeeBoard (Board bo) {
		bo.ShowStep();
	}
	
	public static void main(String[] args) {
		int start_x, start_y; //    
		int board_x, board_y; //   
		Human sehwan = new Human();
		Roach roach = new Roach();
		
		board_x = Integer.parseInt(JOptionPane.showInputDialog(null, "격 기"));
		board_y = Integer.parseInt(JOptionPane.showInputDialog(null, "격 기"));
		start_x = Integer.parseInt(JOptionPane.showInputDialog(null, " "));
		start_y = Integer.parseInt(JOptionPane.showInputDialog(null, " "));
		//   (0,0)
								
		Board board = new Board(board_x, board_y);
		
		sehwan.PutRoach(roach, board, start_x, start_y); //  
		sehwan.SeeBoard(board); 						 //    

	}
}

1.객

.객
:객
:객
) - 객
,,,,,기 -
,기 , , 경 -

계 객 ->
->
-> ()


(Encapsulation):
.
(modularity)과 (information hiding) .
각각 .
근 권 .
(Message):
.
, , .
(Class):()
.
(Instance):( )

(Object)
(Inheritance)
.
(Polymorphism)
.
(overloading), , (overriding) .

. (객)

~cpp 
class  {

   //  

      

   //  

      

}

~cpp 
  = new ();



 ;

 = new ();
.
public: , ,
private:
protected: , ,
friendly(): ,

.
:
:
->

2.객

.객
~cpp 
( ) {  }

( ) {

  ; //     .

 

}

  = new ( );
.this
.
)
~cpp 
[근권] static  ;

[근권] static  ;

    근)

.()

()

객값.()

.

~cpp 
static =기값;



static =new ;

static {

  



 ;

}

3.

... 계 ...

OOP

, , , , 객, ,


  • ?
    . ^^;
  • public과 protected ?
    ^^. private 과 protected . . . 그 . . 그 . protected . . public . . .

  • ~ ? ^^; 겠군. ? ?
  • . -> -> 꿈.
  • . .
  • 1 .


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:31
Processing time 0.0416 sec