Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
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
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter05 : Circle / CircleMain 본문

JAVA/chapter15_access_modifer

chapter05 : Circle / CircleMain

GAWON 2023. 5. 26. 18:47
package org.joonzis.ex;
public class Ex05_Circle {
	
	// Field
	private int x;
	private int y;
	private double radius;
	
	// Constructor
	public Ex05_Circle() {	
		this(0, 0, 1);
	}
	
	public Ex05_Circle(double radius){
		this(0, 0, radius);
	}
	
	public Ex05_Circle(int x, int y, double radius){
		this.x = x;
		this.y = y;
		this.radius = radius;
	}

	// Method  (Main에서 output만 호출하기 때문에, output에 calcArea,calcCircum이 들어가있으므로,output만 public)
	private double calcArea() {
		return radius * radius * Math.PI;
	}
	private double calcCircum() {
		return 2 * Math.PI * radius;
	}
	
	public void output() {
		System.out.println("중심 좌표 : [ " + x + " , " + y + " ]");
		System.out.println("반지름 : " + radius);
		System.out.println("크기 : " + calcArea());
		System.out.println("둘레 : " + calcCircum());
	}
}
package org.joonzis.ex;

public class Ex05_CircleMain {

	public static void main(String[] args) {
		
		Ex05_Circle circle1 = new Ex05_Circle();
		Ex05_Circle circle2 = new Ex05_Circle(1.5);
		Ex05_Circle circle3 = new Ex05_Circle(3, 3, 2.5);

		circle1.output();
		System.out.println();
		circle2.output();
		System.out.println();
		circle3.output();
	}

}

'JAVA > chapter15_access_modifer' 카테고리의 다른 글

chapter07 : Triangle / TriangleMain  (0) 2023.05.26
chapter06 : Local / LocalMain  (0) 2023.05.26
chapter04 : Book / BookMain  (0) 2023.05.26
chapter03 : person / personmain  (0) 2023.05.26
chapter02 : Student / StudentMain  (0) 2023.05.26