군우 2018. 1. 17. 16:44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* 밑변과 높이 정보를 저장할 수있는 triangle 클래스를 정의하자
 * 그리고 생성과 동시에 초기화하는 생성자도 정의하자.
 * 밑변과 높이 정보를 변경 시킬 수 있는 메소드와
 * 삼각형의 넓이를 계산해서 반환하는 메소드도 정의하자.
 */
package class07;
 
public class class0701 {
    public static void main(String[] args)
    {
        int val = 0;
        
        triangle tri = new triangle(0,0);
        tri.change(30,40);
        val=tri.area();
        
        System.out.printf("value : %d ",  val);
    }
}
class triangle
{
    int len;
    int hight;
    
    public triangle(int x, int y) // 생성자만 void안써도 되네.
    {
        len =x;
        hight =y;
    }
    public void change(int x, int y){
        len =x;
        hight = y;
    }
    public int area(){
        int s = len*hight/2;
        return s;
    }
}
cs


value : 600