JAVA/chapter15_access_modifer
chapter07 : Triangle / TriangleMain
GAWON
2023. 5. 26. 18:48
package org.joonzis.ex;
public class Ex07_Triangle {
// Field
private int width;
private int height;
// Constructor
public Ex07_Triangle(){
this(1, 1);
}
public Ex07_Triangle(int width, int height){
this.width = width;
this.height = height;
}
// Method
private double calcArea() {
return width * height / 2.0;
}
public void output() {
System.out.println("너비 : " + width);
System.out.println("높이 : " + height);
System.out.println("크기 : " + calcArea());
}
}
package org.joonzis.ex;
public class Ex07_TriangleMain {
public static void main(String[] args) {
Ex07_Triangle semo1 = new Ex07_Triangle();
Ex07_Triangle semo2 = new Ex07_Triangle(3, 5);
semo1.output();
System.out.println("----------------");
semo2.output();
}
}