Untitled

package myspace3;

public class MaxCounter_Main {

	public static void main(String[] args) {
		MaxCounter maxCount = new MaxCounter(3);
		
		maxCount.increment(); //count 0 -> count++ 1
		maxCount.increment(); //count 1 -> count++ 2
		maxCount.increment(); //count 3 -> count++ 3
		maxCount.increment(); 
		
		
		int count = maxCount.getCount();
		System.out.println(count);
		
	}

}
package myspace3;

public class MaxCounter {
		private int count;
		int max;

		MaxCounter(int max) {
		 	this.max = max;
		}

		void increment() {
			if (max <= count) {
				System.out.println("최대값을 초과할 수 없습니다.");//기준 수령이 범위에 포함되지 않으면서 그 위인 경우
			} else {
				count++;
			}
	}

	int getCount() {
		return count;
   }
}