본문내용
알고리즘
}
public void makeMabangjin() {
int total;
matrix = new int[number][number];
total = number * number;
initMatrix();
if (even) {
evenMabangjin(total);
}
else {
oddMabangjin(total);
}
displayMatrix();
//배열을 초기화 하고, 입력된 차수의 홀수 짝수 여부에 따라 적절한 메소드를 호출한다. 결과를 얻은 후 display() 메소드를 호출하여 화면에 출력한다.
}
}
public class Start {
public static void main(String[] args) {
try {
Mabangjin start = new Mabangjin();
start.makeMabangjin();
//Mabangjin 객체를 생성하고, start.makeMabangjin() 메소드를 호출함
//입력중 예외가 발생할 수 있으므로 try 문 안에서 실행됨
}
catch (Exception e) {}
;
}
}
°소스 분석
프로그램은 Mabangjin.class, Start.class 두 개의 클래스로 이루어져 있다. Start 클래스는 Mabangjin 클래스의 객체를 생성한 후에 Mabangjin클래스의 makeMabangjin() 메소드를 호출하여 마방진을 생성 출력하게 된다.
°소감
프로그램을 작성하면서 메소드를 역할에 맞게 분배 하도록 노력하였고, 그러한 과정을 통해 클래스의 필드와 메소드의 역할에 대한 분명한 이해를 할 수 있는 기회가 되었다.
}
public void makeMabangjin() {
int total;
matrix = new int[number][number];
total = number * number;
initMatrix();
if (even) {
evenMabangjin(total);
}
else {
oddMabangjin(total);
}
displayMatrix();
//배열을 초기화 하고, 입력된 차수의 홀수 짝수 여부에 따라 적절한 메소드를 호출한다. 결과를 얻은 후 display() 메소드를 호출하여 화면에 출력한다.
}
}
public class Start {
public static void main(String[] args) {
try {
Mabangjin start = new Mabangjin();
start.makeMabangjin();
//Mabangjin 객체를 생성하고, start.makeMabangjin() 메소드를 호출함
//입력중 예외가 발생할 수 있으므로 try 문 안에서 실행됨
}
catch (Exception e) {}
;
}
}
°소스 분석
프로그램은 Mabangjin.class, Start.class 두 개의 클래스로 이루어져 있다. Start 클래스는 Mabangjin 클래스의 객체를 생성한 후에 Mabangjin클래스의 makeMabangjin() 메소드를 호출하여 마방진을 생성 출력하게 된다.
°소감
프로그램을 작성하면서 메소드를 역할에 맞게 분배 하도록 노력하였고, 그러한 과정을 통해 클래스의 필드와 메소드의 역할에 대한 분명한 이해를 할 수 있는 기회가 되었다.
소개글