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.0194 sec