/*

오버로딩(다중정의)

  1. 자바 다형성구현기법 중의하나이다.

  2. 정의: 같은메쏘드 이름으로 여러개를 정의하는방법

           - 규칙: 

               * 메쏘드의 이름이 같아야한다.

               * 메쏘드의 인자의 숫자가 다르거나

               * 메쏘드의 인자의 타입이 달라야한다.

               * 메쏘드의 리턴타입,접근지정자는 상관없다.


*/

//------ Printer.java ------

 

public class Printer {
	public void print (int a){
		System.out.println("int print: "+a);
	}
	public void print (char c){
		System.out.println("char print: "+c);
		
	}
	public void print (String str){
		System.out.println("String print: "+str);
		
	}
	public void print (boolean b){
		System.out.println("boolean print: "+b);
		
	}
	public void booleanprint (boolean b){
		System.out.println("boolean print2: "+b);
		
	}
	
	public static void main(String[] args) {
		Printer p = new Printer();
		
		p.print(false);
		p.booleanprint(true); //얘는 오버로딩 안하고 그냥 쓰는거.
		p.print("U");
		p.print(7);
		p.print("HAVE A GOOD TIME");
	
	}
}

 

//------ Overloading.java ------

 
public class Overloading {

	public void method (){
		System.out.println("public void method ()");
	}
	
	public void method (int a){
		System.out.println("public void method (int a)= "+a);
	}
	
	//인자의 타입
	public void method (float a){
		System.out.println("public void method (float a)= "+a);	
	}
	public void method (char a){
		System.out.println("public void method (char a)= "+a);
	}
	
	//인자의 수
	public void method (int a, int b){
		System.out.println("public void method (int a, int b)= "+a+", "+b);
	}
	/*
	//메소드 리턴타입
	public void method1 (){
		
	}
	public int method1 (){
		return 0;
	}
	
	//접근 지정자
	public void method2 (){
		
	}
	private void method2 (){
		
	}
	*/
	public static void main(String[] args) {
		Overloading ol = new Overloading();
		
	ol.method() ;
	ol.method(3.1f);
	ol.method(3);
	ol.method('K');
	ol.method(1, 2);

	}
}

 

/* OOP 의 원칙 

*   1. 캡슐화

*   2. 상속성

*   3. 다형성(오버로딩,오바라이딩,객체형변환)

*/


/*

* 1. 캡슐화

*    - 외부클래스나 객체에서 멤버변수에 접근을 막고

*      멤버 메쏘드에만 접근할수있도록 클래스를 설계하는방법

*    - 구현 : 멤버변수의 접근제한자를 private 

*       멤버메소드의 접근제한자는 public 으로한다. 

*             public ==> 어떤 외부클래스에서든지 접근가능

*             private==> 어떤 외부클래스에서든지 접근불가능

*/



Account

/*
 * - 은행의 계좌 객체를 추상화한 클래스이다.
 * - 은행계좌의 데이터를 가지고 있는 클래스이다.
 * 
 */
public class Account {
	private String no; //계좌번호
	private String owner; //계좌주
	private int balance; //잔액
	private float iyul; //이율
	
	/*
	 * 입금하다
	 */
	/**
	 * 
	 * @param money 입금금액
	 */
	public void ipGum (int money){
		this.balance = this.balance + money;
		System.out.println(" << 입 금 완 료 >> ");
		System.out.println("입 금 금 액: " + money);
		this.print();
	}
	
	/*
	 * 출금하다
	 */
	/**
	 * 
	 * @param money 출금금액
	 * @return 출금가능 여부
	 */
	public boolean chulGum(int money){
		boolean isSuccess = false;
		
		if (this.balance < money){
			isSuccess = false;
		}
		else {
			this.balance = this.balance - money;		
			isSuccess = true;
		}
		return isSuccess;
		
	}
	/*
	 * 계좌정보를 출력하다.
	 */
	/**
	 * 계좌 정보를 인출한다.
	 */
	public void print (){
		System.out.println("==========================");
		System.out.println("계 좌 번 호: "+ this.no +"\n"
				+ "계 좌 주 명: " + this.owner +"\n"
				+ "계 좌 잔 액: "+ this.balance +"\n"
				+ "계 좌 이 율: "+ this.iyul);
		System.out.println("==========================");
		
	}

	public String getNo() {
		return no;
	}

	public String getOwner() {
		return owner;
	}

	public int getBalance() {
		return balance;
	}

	public float getIyul() {
		return iyul;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public void setBalance(int balance) {
		this.balance = balance;
	}

	public void setIyul(float iyul) {
		this.iyul = iyul;
	}
	
	
}

 

AccountMain

public class AccountMain {

	public static void main(String[] args) {
		Account acc1 = new Account();
		/*
		acc1.no ="111";
		acc1.owner ="김경수";
		acc1.balance =5000;
	*/
		acc1.setNo("111");
		acc1.setOwner("김경수");
		acc1.setBalance(5000);
		acc1.setIyul(4.5f);
		
		//입금
//		acc1.balance = acc1.balance + 3000;
		acc1.ipGum(3000);
		
		//출금
		boolean isSuccess = acc1.chulGum(56000);
		if (isSuccess == true){
			System.out.println(" << 출 금 완 료 >>"
								+"\n 잔액: "+acc1.getBalance());
		}
		else {
			System.out.println(" << 잔 액 부 족 >>"
								+"\n 잔액: "+acc1.getBalance());
		}
		
		isSuccess = acc1.chulGum(4000);
		if (isSuccess == true){
			System.out.println(" << 출 금 완 료 >>"
								+"\n 잔액: "+acc1.getBalance());
		}
		else {
			System.out.println(" << 잔 액 부 족 >>"
								+"\n 잔액: "+acc1.getBalance());
		}
		//출력
		acc1.print();	
	}//end main

}//end class

 

OOP: 객체지향 프로그래밍(Object Oriented Programming)

 - 우리 일상에서이루어지고있는 업무를 객체(Object)를 사용해서  프로그래밍하는방법

 - ex)  

*    1. 실제 주차장관리 업무파악

*      (객체를 도출하고 그객체들의 관계에의한 업무파악) 

*    2. 프로그램으로 작성 

*      (1번에서 파악된업무를 메모리상에서 그대로구현) 

*   

*    ex> 주차관리 프로그램 

*     

*   - 객체(업무):실제이루어지고있는 업무(주차장)에서 보여지고구체화되어있는 사물(차)    

*   

*   - 객체(프로그램):실제이루어지고있는 업무(주차장)에서 보여지고

*                  구체화되어있는 사물을 메모리의 데이타로

*                  표현한것(차의데이타)


OOP 의 원칙 

1. 캡슐화

2. 상속성

3. 다형성(오버로딩,오바라이딩,객체형변환)





//------ Car.java ------

/*TIP:
 * class 선언
 *  - 형식
 *       접근제한자  class  클래스이름{
 *       	- 접근제한자:public,protected,없는거
 *       
 *       } 
 *       ex> public class Car{
 *           }
 *           
 *  -구성요소
 *     1.멤버변수선언(속성)
 *        접근제한자(public,proected,없는거,private) 타입 indentifier;
 *        ex> public String carName;
 *        
 *     2.멤버메쏘드 선언(행위)    
 *        접근제한자 리턴타입 메쏘드이름(인자){
 *           -인자: 나를 호출한놈이 데이타를 넣어줄 통로
 *        	 -리턴타입: 나를 호출한놈에게 줄 데이타타입 
 *                     void --> 줄데이타가 없는경우
 *        }
 *        ex> public int test(int a){
 *        	  	
 *            }
 */

/**
 * 
 * 이 클래스는 Car 클래스이다.
 * 차 번호와 입차, 출차시간, 요금을 받는다.
 * @author : SUIN
 * @version: ver0.1
 *
 */
public class Car {
	/**
	 * 차량의 번호
	 */
	public String no ;
	public int inTime;
	public int outTime;
	/** 요금저장 */
	public int fee;
}

//------ CarMain.java ------

 

public class CarMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//1. 차가 들어온다. (입차)
			//변수선언 : 타입 식별자 -> Car 타입
		
		//차 클래스 사용해서 차 객체 생성 후 Car 변수 초기화
			//*Car 타입의 기억장소 c1이라는 식별자 할당, 
			//*Car 클래스(틀)을 활용해서 객체 생성
		
		Car c1 = new Car(); //차 객체 찍기
		
		//차 객체 안의 멤버변수 초기화
		c1.no ="1234";
		c1.inTime = 12;
		c1.outTime = 0;
		c1.fee = c1.outTime - c1.inTime;
		
		//시간이 흐른 후 (2hr)
		
		//2. 요금계산
		c1.outTime = 14;
		c1.fee = (c1.outTime - c1.inTime)*1000;
		
		//3. 출력
		System.out.println("****************");
		System.out.println("차량번호: "+c1.no
				+"\n입차시간: "+c1.inTime
				+"\n출차시간: "+c1.outTime
				+"\n주차요금: "+c1.fee+"원");
		System.out.println("****************");
		
		/*****************************************/
		//String str;
		
		Car c2 = new Car(); 
		c2.no ="4962";
		c2.inTime = 14;
		c2.outTime = 0;
		c2.fee = 0;
		c2.outTime = 17;
		c2.fee = (c2.outTime - c2.inTime)*1000;

		System.out.println("****************");
		System.out.println("차량번호: "+c2.no
				+"\n입차시간: "+c2.inTime
				+"\n출차시간: "+c2.outTime
				+"\n주차요금: "+c2.fee+"원");
		System.out.println("****************");
	}

}
 

//------ CarMethod.java ------

/* class 선언
 *  - 형식
 *       접근제한자  class  클래스이름{
 *       	- 접근제한자:public,protected,없는거
 *       
 *       } 
 *       ex> public class Car{
 *           }
 *           
 *  -구성요소
 *     1.멤버변수선언(속성)
 *        접근제한자(public,proected,없는거,private) 타입 indentifier;
 *        ex> public String carName;
 *        
 *     2.멤버메쏘드 선언(행위)    
 *        접근제한자 리턴타입 메쏘드이름(인자){
 *           -인자: 나를 호출한놈(클래스,객체)이 데이타를 넣어줄 통로
 *        	 -리턴타입: 나를 호출한놈에게 줄 데이타타입 
 *                     void --> 줄데이타가 없는경우
 *        }
 *        ex> public int test(int a){
 *        	  	
 *            }
 */
/**
 * @author : SUIN
 * @since 201302
 * 
 */
public class CarMethod {
/**
 * 차량의 번호 : String 형태
 */
	public String no ;
	/**
	 * 입차시간
	 */
	public int inTime;
	public int outTime;
	public int fee;
	public static int moneyPerHour = 1000;
	
	/*
	 * 기능 (메서드)
	 * 1. 요금을 계산하다
	 * 2. 출력하다
	 */

	
	//요금 계산
	/**
	 * 요금 계산 메소드
	 */
	public void calculateFee() {
		this.fee = (this.outTime - this.inTime)*moneyPerHour;
		//같은 클래스 안에서는 자기자신의 레퍼런스이므로 this. 해주면 됨. 
		//안해줘도 default 로 생략가능.(처음엔 생략하지 말 것)
		// this = 셀프참조변수
	}
	
	//출력
	/**
	 * 차량의 주차정보 출력 메소드
	 */
	public void print(){
		System.out.println("****************");
		System.out.println("차량번호: "+this.no
				+"\n입차시간: "+inTime
				+"\n출차시간: "+outTime
				+"\n주차요금: "+fee+"원");
		System.out.println("****************");
	}
	
	//초기화
	/**
	 * 차량의 데이터를 SET 
	 * 
	 * @param no :차량 번호 입력
	 * @param inTime :입차시간 
	 * @param outTime :출차시간
	 * @param fee :주차요금
	 * 
	 */
	public void setData(String no, int inTime, int outTime, int fee){
		this.setNo(no);
		this.setInTime(inTime);
		this.setOutTime(outTime);
		this.setFee(fee);
	}

	/*
	 * 멤버필드 데이터 메소드(set, get)
	 * 1. setter method
	 * 2. getter method
	 */
	//setter method
	public void setNo (String no){ //검정은 로컬변수
		this.no = no;	//파랑은 멤버(전역)변수
				//
	}
	public void setInTime(int inTime){
		this.inTime = inTime;
	}
	public void setOutTime(int outTime){
		this.outTime = outTime;
	}

	public void setFee(int fee) {
		this.fee = fee;
	}

	//getter method
	/**
	 * 차량 번호를 반환하는 메소드
	 * @return 
	 */
	public String getNo (){ //get : 다른 클래스(사용자) 입장에서 get
		return this.no;
	}
	public int getInTime (){
		return this.inTime;
	}

	public int getOutTime() {
		return outTime;
	}

	public int getFee() {
		return fee;
	}
		//Source - Generate getter and setter -> 자동으로 만들어줌. 대박!

}

//------ CarMethodMain.java ------

public class CarMethodMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//1. 차가 들어온다. (입차)
			//변수선언 : 타입 식별자 -> Car 타입
		
		//차 클래스 사용해서 차 객체 생성 후 Car 변수 초기화
			//*Car 타입의 기억장소 c1이라는 식별자 할당, 
			//*Car 클래스(틀)을 활용해서 객체 생성
		
		CarMethod c1 = new CarMethod(); //차 객체 찍기
		
		//차 객체 안의 멤버변수 초기화
		c1.no ="3456";
		c1.inTime = 12;
		c1.outTime = 0;
		c1.fee = 0;
		
		//시간이 흐른 후 (2hr)
		c1.outTime = 14;
		//2. 요금계산
				c1.outTime = 14;
				c1.fee = (c1.outTime - c1.inTime)*1000;
				
				//3. 출력
				System.out.println("****************");
				System.out.println("차량번호: "+c1.no
						+"\n입차시간: "+c1.inTime
						+"\n출차시간: "+c1.outTime
						+"\n주차요금: "+c1.fee+"원");
				System.out.println("****************");
		
				
			/******************클래스에 메소드추가***************************/
		CarMethod c2 = new CarMethod(); //번지수 입력, this = c2의 주소
		c2.no ="1212";
		c2.inTime = 13;
		c2.outTime = 0;
		c2.fee = 0;
		c2.outTime = 17;
		c2.calculateFee(); //요금 계산 함수
		c2.print(); //요금 출력 -> 우와 편해졌다! 

		
			/********************getter,setter*************************/
		CarMethod c3 = new CarMethod();
		//데이터에 관련된 메소드. setter method, getter method
		//1. 입차
		c3.setData("1234", 16, 0, 0);
		
		//2. 시간이 흐른 후
		c3.setOutTime(17);
		c3.calculateFee();
		
		//3. 출력
		c3.print();
		
		//*.번호 알아보기
		String no = c3.getNo();
		System.out.println("no="+no);

		/*
		 * Car 클래스를 사용하는 사용자에게 
		 * Car 클래스의 멤버에 대해 설명하지 않아도 됨.
		 * 메소드만 설명하면 되고, 사용자가 멤버변수를 몰라도 됨.
		 * 
		 *  => 다른 클래스, 객체의 멤버변수 접근을 막는다. 
		 */
		
		//시간당 요금 출력
		System.out.println("시간당 요금: "+CarMethod.moneyPerHour);
			}
}

//------ MemberField.java ------

public class MemberField {

	//선언과 동시에 초기화 가능
	/*
	 * 객체 생성 후 멤버변수의 초기 기본값
	 * 
	 * 참조변수 (클래스변수, 객체변수)	: null
	 * integer								: 0
	 * boolean 							: false
	 * double							:0.0
	 * 
	 */
	public String member1 = "멤버변수연습";
	public int member2 = 130222;
	public char member3 ;
	public boolean member4 ;
	public float member5 ;
	  
	
}

//------ MemberFieldMain.java ------

public class MemberFieldMain {

	public static void main(String[] args) {
		
		/*선언*/
		MemberField mf; 
		//MemberField.class가 존재해야 레퍼런스 변수 선언 가능
		//선언하면 멤버필드 템플릿이 메모리 위로 올라옴.
		//mf = MemberField 객체의 주소값을 가짐
		
		/*초기화*/
		mf = new MemberField();
		// 보통 선언과 동시에 초기화 MemberField mf = new MemberField();

		/*
		 * << 멤버(객체)변수  접근 방법 >>
		 * 
		 *  - 참조변수.멤버변수의 식별자
		 *  
		 *  ex> Student st = new Student();
		 *  	st.no = 1234;
		 * 
		 */
		mf.member1 ="문자열";
		mf.member3='c';
		mf.member5=3.14159f;
		
		System.out.println(mf.member1);
		System.out.println(mf.member2);
		System.out.println(mf.member3);
		System.out.println(mf.member4);
		System.out.println(mf.member5);
				
				//tip: Ctrl+마우스 왼클릭 = 해당 변수가 정의 된 곳으로 이동
				//tip: Ctrl+Alt+↓,↑ = 해당 드래그 된 내용 복사 붙여넣기

	}
}

//------ MemberMethod.java ------

/*
          
 *  -구성요소
 *     1.멤버변수선언(속성)
 *        접근제한자(public,protected,없는거,private) 타입 indentifier;
 *        ex> public String carName;
 *        
 *     2.멤버메쏘드 선언(행위)    
 *        접근제한자 리턴타입 메쏘드이름(인자){
 *           -인자: 나를 호출한놈이 데이타를 넣어줄 통로
 *        	 -리턴타입: 나를 호출한놈에게 줄 데이타타입 
 *                     void --> 줄데이타가 없는경우
 *        }
 *        ex> public int test(int a){
 *        	  	
 *            }
 *            
 *            //리턴타입과 메쏘드이름 사이는 떨어지면 안된다.
 */

public class MemberMethod {
	
	public void method1 () {
		System.out.println("method1()실행");
	}
	public void method2 (int a){
		System.out.println("method2(int a)실행: "+a);
	}
	public void method3(int a, int b){
		System.out.println("method3(int a, int b)실행: "+a+","+b);
	}
	public int method4 (int a){
		a = a+1;
		System.out.print("mothod4(int a)실행: ");
		return a;
	}
	public int method5 (int a, int b){
		int result = a+b ;
		System.out.print("mothod5(int a, int b)실행: ");
		
		return result;
	}
}

//------ MemberMethodMain.java ------

public class MemberMethodMain {

	public static void main(String[] args) {

		MemberMethod mm = new MemberMethod();
		/*
		 * 멤버(객체)메쏘드에 접근하는방법
		 * 
		 * -형태: 참조(객체)변수.메쏘드이름();
		 * ex> mm.method1();
		 */
		
		mm.method1();
		mm.method2(3);
		mm.method3(1, 2);
		
		int result = mm.method4(999);
		System.out.println(result);
		/*
		 * public int method5(int x, int y);
		 */
		result = mm.method5(34, 34457833);
		System.out.println(result);
	}
}

//------ CH02. ForTest- for 문 기본 ------
/*
	for문
	     -형식:
	       	       
	       for(1;2;3){
	       	//1.반복변수(선언,초기화가능)
	       	 * 	 -> 타입과 identifier -> 변수의 구조와크기
	       	//2.반복변수의 조건검사(논리형데이타)
	       	//3.반복변수증,감(++,--)
	       }
	       
	       ex>
	       for(int i=0;i<10;i++){
	       	 stmt1;
	       }
	       ex>무한루프
	       for(;;){
	       	
	       }
	       	* -> 무한루프도 OCJP출제
	
	*/
public class ForTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int i, j;
		//****구구단*****
		System.out.println("\n===============구구단 출력==============");
		for (i=1; i<10; i++){
			for (j=2;j<10; j++){
				System.out.print(j+" X "+i+" = "+i*j+"\t");
			}
			System.out.println();
		}
		System.out.println("\n===============modular for test ==============");
		
		//*****modular 4*******
		System.out.print("1~10 중 4로 나누어 떨어지는 수는 ");
		for (i=1; i<=10; i++){
			if (i%4 == 0){
				System.out.print(i+", ");
			}
		}
		System.out.println("이다.");
		
		
		//******1~10 중 홀수 합
		System.out.println("\n==============sum of odd while 1 to 10===============");

		int sum=0;
		
		for (i=1; i<=10; i++){
			if(i%2 ==1){
				sum+=i;
				/*
				 * 연산 후 대입 연산자
				 * 
				 * a+=b; == a=a+b;
				 * a-=b; == a=a-b;
				 * a*=b; == a=a*b;
				 * a/=b; == a=a/b;
				 * 
				 */
			}
		}
		System.out.println("1~10까지 홀수의 합은 "+sum+"이다.");

		//******알파벳 소문자 출력
		System.out.println("\n==============small alphabet print===============");
		char alphabet = 'a';
		int count=0;
		for (alphabet = 'a'; alphabet<= 'z' ; alphabet++){
			System.out.print(alphabet+" ");
			count ++;
			
			if (count%4 == 0){
				System.out.println();
			}
		}
		
		//감소
		count =0;
		System.out.println("\n==============for 감소===============");
		for (alphabet = 'z'; alphabet>= 'a' ; alphabet--){
			System.out.print(alphabet+" ");
			count ++;
			
			if (count%4 == 0){
				System.out.println();
			}
		}
		
		//2씩 증가
		System.out.println("\n==============2씩 증가===============");
		for (i =0; i<100; i+=2){
			System.out.print(i+" ");
		}
		
		//2씩 감소
		System.out.println("\n==============2씩 감소===============");
		for (i=100; i>0; i-=2){
			System.out.print(i+" ");
		}
		
		
	}//end main

}
 
===============구구단 출력==============
2 X 1 = 2	3 X 1 = 3	4 X 1 = 4	5 X 1 = 5	6 X 1 = 6	7 X 1 = 7	8 X 1 = 8	9 X 1 = 9	
2 X 2 = 4	3 X 2 = 6	4 X 2 = 8	5 X 2 = 10	6 X 2 = 12	7 X 2 = 14	8 X 2 = 16	9 X 2 = 18	
2 X 3 = 6	3 X 3 = 9	4 X 3 = 12	5 X 3 = 15	6 X 3 = 18	7 X 3 = 21	8 X 3 = 24	9 X 3 = 27	
2 X 4 = 8	3 X 4 = 12	4 X 4 = 16	5 X 4 = 20	6 X 4 = 24	7 X 4 = 28	8 X 4 = 32	9 X 4 = 36	
2 X 5 = 10	3 X 5 = 15	4 X 5 = 20	5 X 5 = 25	6 X 5 = 30	7 X 5 = 35	8 X 5 = 40	9 X 5 = 45	
2 X 6 = 12	3 X 6 = 18	4 X 6 = 24	5 X 6 = 30	6 X 6 = 36	7 X 6 = 42	8 X 6 = 48	9 X 6 = 54	
2 X 7 = 14	3 X 7 = 21	4 X 7 = 28	5 X 7 = 35	6 X 7 = 42	7 X 7 = 49	8 X 7 = 56	9 X 7 = 63	
2 X 8 = 16	3 X 8 = 24	4 X 8 = 32	5 X 8 = 40	6 X 8 = 48	7 X 8 = 56	8 X 8 = 64	9 X 8 = 72	
2 X 9 = 18	3 X 9 = 27	4 X 9 = 36	5 X 9 = 45	6 X 9 = 54	7 X 9 = 63	8 X 9 = 72	9 X 9 = 81	

===============modular for test ==============
1~10 중 4로 나누어 떨어지는 수는 4, 8, 이다.

==============sum of odd while 1 to 10===============
1~10까지 홀수의 합은 25이다.

==============small alphabet print===============
a b c d 
e f g h 
i j k l 
m n o p 
q r s t 
u v w x 
y z 
==============for 감소===============
z y x w 
v u t s 
r q p o 
n m l k 
j i h g 
f e d c 
b a 
==============2씩 증가===============
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 
==============2씩 감소===============
100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 
//------ CH02. ForGuGuDan- for문을 이용한 구구단 ------
public class ForGuGuDan {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int i, j;
		//****구구단*****
		System.out.println("\n===============구구단 출력==============");
		for (i=1; i<10; i++){
			for (j=2;j<10; j++){
				System.out.print(j+" X "+i+" = "+i*j+"\t");
			}
			System.out.println();
		}
	}

}
 
//------ CH02. ForNested- for문으로 별 찍기 ------
		/*
		 ☆★★★★
		 ★☆★★★
		 ★★☆★★
		 ★★★☆★
		 ★★★★☆ 
		 */
public class ForNested {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int i, j;

		
		System.out.println("*****별 찍기 1*****\n");
		for (i=0; i<5; i++){
			for (j=0; j<5; j++){
				if (i == j){
					System.out.print("☆");
				}
				else{
				System.out.print("★");
				}
			}
			System.out.println();
		}
		
		
		System.out.println("*****별 찍기 2*****\n");
		/*
		 ★☆☆☆☆
		 ★★☆☆☆
		 ★★★☆☆
		 ★★★★☆
		 ★★★★★ 
		 */
		for (i=0; i<5; i++){
			for (j=0; j<=i; j++){
				System.out.print("★");
			}
			for (int k=4; k>i; k--){
				System.out.print("☆");
			}
			System.out.println("");
		}
		

		System.out.println("*****별 찍기 3*****\n");
		/*
		 ☆☆☆☆★ 
		 ☆☆☆★★ 
		 ☆☆★★★ 
		 ☆★★★★ 
		 ★★★★★ 
		 */
		for (i=0; i<5; i++){
			for (j=4; j>i; j--){
				System.out.print("☆");
			}
			for (int k=0; k<=i; k++){
				System.out.print("★");
			}
			System.out.println();
		}
		

		System.out.println("*****별 찍기 4*****\n");
		/*
		 ★★★★★
		 ★★★★
		 ★★★
		 ★★
		 ★ 
		 */		
		for (i=0; i<5; i++){
			for (j=5; j>i; j--){
				System.out.print("★");
			}
			System.out.println();
		}
		
		
	}//end main

}

 
//------ CH02. Switch,While - 정수 홀짝 구분, 알파벳 출력 ------
import java.util.Scanner;

/*
 * 1.정수를 입력받아서 짝수인지 홀수인지 출력(switch)

2.알파벳 대문자출력(4개찍고 개행)(while)
   ex> ABCD
       EFGH
       IJKL
       ...
	
		 

 */
public class HomeWork_3_0220 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

//정수를 입력받아서 짝수인지 홀수인지 출력(switch)	
		Scanner sc = new Scanner(System.in);
		
		int num; 
		int nextLine =0;
		int alphabet =65;
		char alpha ='A'; //int 65
		
		System.out.println("숫자하나 입력");
		num = sc.nextInt();
		
		num = num%2;
		
		switch (num){
		case 1:
			System.out.println("홀수");
			break;
			
		case 0:
			System.out.println("짝수");
			break;
		
		}
		
//알파벳 대문자출력(4개찍고 개행)(while)
		num =0;
		
		while (num < 26){
			System.out.print(alpha);
			nextLine++;
			while (nextLine > 4){
				System.out.println("");
				nextLine =0;
			}
			num++;
			alpha++;	
		}

	}

}

 
//------ CH02. SwitchScoreTest - switch 문으로 점수 구분하기 ------
import java.util.Scanner;


public class SwitchScoreTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		
		Scanner sc = new Scanner(System.in);
		
		int kor,eng,math;
		kor=71;
		eng=52;
		math=91;

		System.out.println("국어,영어,수학 점수 입력");
		kor = sc.nextInt();
		eng = sc.nextInt();
		math = sc.nextInt();
		
		int total = kor+eng+math;
		float everage = (float)total/3; 
		char hakjum;
		
		everage = everage*100;
		int trans = (int)everage;
		everage = (float)trans/100;

		int switch_triger = (int)everage/10;
		
		/**점수 타당성 검사 **/

		if (kor<0 || kor>100){
			System.out.println("ERROR, SCORE is Between 0 to 100");
			return; //해당 경우에 하위 문장을 실행하지 않고 return
		}
		if (eng<0 || eng>100){
			System.out.println("ERROR, SCORE is Between 0 to 100");
			return; //해당 경우에 하위 문장을 실행하지 않고 return
		}
		
		if (math<0 || math>100){
			System.out.println("ERROR, SCORE is Between 0 to 100");
			return; //해당 경우에 하위 문장을 실행하지 않고 return
		}
		
		System.out.println("************************");
		System.out.println("국어: "+kor);
		System.out.println("영어: "+eng);
		System.out.println("수어: "+math);
		System.out.println("총점: "+total);
		System.out.println("평균: "+everage);
		
		switch (switch_triger){
		case 10:
			hakjum='S';
			break;
		case 9:
			hakjum = 'A';
			break;
			
		case 8:
			hakjum = 'B';
			break;
		case 7:
			hakjum = 'C';
			break;
		case 6:
			hakjum ='D';
			break;
			
		default:
			hakjum ='F';		
		}

		System.out.println("평점: "+hakjum);
		System.out.println("************************");
	}

}
 
//------ CH02. whileGuGuDan- while문을 이용한 구구단 ------
public class WhileGuGuDan {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int i=1, j=2;
		
		while (i<10){
			while (j<10){
				System.out.print(j+" X "+i+" = "+i*j+"\t");
				j++;
			}
			j =2;
			System.out.println();
			i++;
		}
	}//end main

}//and class

 


//------ CH01. ArithmaticOperator - 산술 연산자 ------
/*
 산술연산자
          - 형태:  +,-,*,/,%
 */

public class ArithmaticOperator {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  int a = 1, b = 2;
  int result = a + b;
  float result1;
  
  System.out.println("a+b = " +result );
  
  result = a - b;
  System.out.println("a-b = " +result );
  
  result = a * b;
  System.out.println("a*b = " +result );
  
  result1 = (float)a/b;
  System.out.println("a/b = " +result1 );
  
  result = a % b;
  System.out.println("a%b = " +result );
  
  result = 452%52;
  System.out.println("452%52 = "+result);
 }

}
//------ CH01. BitOrerator - 비트 연산자 ------
/*  
  비트연산자
    -형태: | , & ,~,>>,<<
      * ~ : not (모든 비트 반전)
  

  Bit or 연산( | )   -->양쪽비트가 모두 0인경우에만 0을반환
  Bit and 연산 ( & ) -->양쪽비트가 모두 1인경우에만 1을반환
   *||, &&와 다른 점: |, &는 양쪽이 논리형(t,f)이면 논리형 연산을 함
   *정수형이면 정수형 연산을 함.
  Shift 연산자 >>,<< --> bit를 좌우측으로 이동
*/

public class BitOrerator {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  int i1 = 3;
  int i2 = 5;
  int i3 = 7;
  
  int result = i1 | i2;
  System.out.println("3|5 = "+result);
  /*
   *  3  =  0000 0000 0000 0000 0000 0000 0000 0011 (4byte = 8bit)
   *  5  =  0000 0000 0000 0000 0000 0000 0000 0101
   *  3|5 = 0000 0000 0000 0000 0000 0000 0000 0111 = 7 
   *  3&5 = 0000 0000 0000 0000 0000 0000 0000 0001 = 1
   */
  
  result = ~i1;
  System.out.println("~3 = "+result);
  /*
   * 2의 보수 역과정
   *  3  =  0000 0000 0000 0000 0000 0000 0000 0011 
   *  ~3 =  -4
   *   *읽는 방법: 모든 비트를 뒤집음 -> 값 +1 (보수를 취한 후 +1)
   *    1111 1111 1111 1111 1111 1111 1111 1100 ->뒤집음
   *    값 +1
   *    1111 1111 1111 1111 1111 1111 1111 1101
   *   다시 역과정을 거치면 
   *   0000 0000 0000 0000 0000 0000 0000 0010 -> 4인데 
   *   아까 뒤집을 때 맨 앞이 1이니까 -4가 답이 된다.
   *  */
  
  int i = 1;
  
  result =  i<<5;
  System.out.println("1<<1"+result);
  
  boolean bresult = true | false;
  System.out.println("true|false = "+bresult);
  
 }

}
//------ CH01. CastingExam - 형 변환 예제 ------
/*
  형변환(Casting)--> 숫자형데이타간에만 가능
   - 형식 :  (데이타타입)변수or상수;
      - 자동형변환(작은데이타-->큰데이타 기억장소)upcasting
        byte-->short-->int-->long-->float-->double
        묵시적 형 변환
   - 강제형변환(큰데이타-->작은데이타)downcasting
        double-->float-->long-->int-->short-->byte
        명시적 형 변환
  */
  //upcasting(promotion)

public class CastingExam {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  //암시적 형 변환
  byte bt = 10; //내부적으로 형 변환이 일어남 int -> byte
  short st = bt;
  float ft =st;
  
  //명시적 형 변환
  int i =29;
  short s = (short)i;
  double d = 32.1241213;
  int i1  = (int)d;
  
  System.out.println(i);
  System.out.println("(int)"+d+" = "+i1);

  
  //연산시의 형 변환 
  //(가장 큰 항의 데이터 타입으로 모든 항이 UpCasting된 후 연산)
  byte bb = 34;
  short ss = 23;
  int ii = 143;
  long ll = 12423435234L;
  float ff = 23.45f;
  double dd = 234.23423211;
  
  double result = bb+ss+ii+ll+ff+dd;
  
  
  /***예외 : byte와 short의 연산은 무조건 int로 UpCasting 후에 진행***/
  byte bbb =89;
  short sss = 90;
  
  int sResult = bbb+sss;
  
 }

}
//------ CH01. HelloWorld - 문자열 출력 ------
public class HelloWorld {
 public static void main (String[] args){
  //문자열 출력 명령문 (주석)
  System.out.println("Hello java");
  System.out.println("안녕자바!");
 }
}
//------ CH01. IfNested - 중첩 if문 ------
import java.util.Scanner;

/*중첩 if문
 * 
 * 
 */
public class IfNested {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  int kor , eng, math;
  char hakjum = ' ';
  Scanner sc = new Scanner(System.in);
  System.out.println("Enter Your KOR Score");
  kor = sc.nextInt();
  
  if (kor>=0 && kor<=100){
   if (kor > 90){
    hakjum ='A';
   }else if (kor >80){
    hakjum ='B';
   }else if (kor > 70){
    hakjum ='C';
   }else if (kor > 60){
    hakjum ='D';
   }else {
    hakjum ='F';
   }
   System.out.println("Your MATH Grade is "+hakjum);
  }
  else{
   System.out.println("ERROR, SCORE is Between 0 to 100");
  }
  
  System.out.println("\nEnter Your MATH Score");
  math = sc.nextInt();
  if (math<0 || math>100){
   System.out.println("ERROR, SCORE is Between 0 to 100");
   return; //해당 경우에 하위 문장을 실행하지 않고 return
  }
  
  if (math >=90){
   hakjum = 'A';
  }else if (math >=80){
   hakjum = 'B';
  }else if (math >=70){
   hakjum = 'C';
  }else if (math >=60){
   hakjum ='D';
  }else {
   hakjum ='F';
  }
  System.out.println("Your MATH Grade is "+hakjum);
   
 } //end main

}//end class

//------ CH01. IfOddEven - if문 홀짝 ------
import java.util.Scanner;


public class IfOddEven {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int su ;
  Scanner sc = new Scanner(System.in);
  
  System.out.println("숫자를 입력 해주세요.");
  su = sc.nextInt();
  
  String msg ="";
  
  if ( su % 2 ==0){
   msg = "짝수";
  }
  else{
   msg = "홀수";
  }
  System.out.println(su+"은( "+msg+" 입니다");
 }
 
 

}

//------ CH01. IfScoreTest- if문을 이용한 성적 출력 ------
 /*
//Casting을 사용하는 것이 관건!
 * 값이 어떻게 잘리는지 알자 :)
 *   
  국어,영어,수학 점수를 가지고 
  총점,평균,평점(A,B,C....)을 출력하시요....
           - 100점이 넘는 수나 음수가 입력되면 메세지를 출력하세요
           - 평균은 소수점이하 2자리수까지만 출력하세요
           - 출력포맷
    
    ************************
    국어: 78
    영어: 56
    수학: 77
    총점:256
    평균:78.56
    평점: C
    ************************
  */
import java.util.Scanner;
public class IfScoreTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  Scanner sc = new Scanner(System.in);
  
  int kor,eng,math;
  kor=71;
  eng=52;
  math=91;

  System.out.println("국어,영어,수학 점수 입력");
  kor = sc.nextInt();
  eng = sc.nextInt();
  math = sc.nextInt();
  
  int total = kor+eng+math;
  float everage = (float)total/3; 
  char hakjum;
  
  everage = everage*100;
  int trans = (int)everage;
  everage = (float)trans/100;

  
  /**점수 타당성 검사 **/
  if (kor<0 || kor>100){
   System.out.println("ERROR, SCORE is Between 0 to 100");
   return; //해당 경우에 하위 문장을 실행하지 않고 return
  }
  if (eng<0 || eng>100){
   System.out.println("ERROR, SCORE is Between 0 to 100");
   return; //해당 경우에 하위 문장을 실행하지 않고 return
  }
  
  if (math<0 || math>100){
   System.out.println("ERROR, SCORE is Between 0 to 100");
   return; //해당 경우에 하위 문장을 실행하지 않고 return
  }
  
  System.out.println("************************");
  System.out.println("국어: "+kor);
  System.out.println("영어: "+eng);
  System.out.println("수어: "+math);
  System.out.println("총점: "+total);
  System.out.println("평균: "+everage);
  
  
  if (everage >=90){
   hakjum = 'A';
  }else if (everage >=80){
   hakjum = 'B';
  }else if (everage >=70){
   hakjum = 'C';
  }else if (everage >=60){
   hakjum ='D';
  }else {
   hakjum ='F';
  }
  System.out.println("평점: "+hakjum);
  System.out.println("************************");


  
   
 }

}

//------ CH01. IfTest- if문을 이용한 True, False ------
/*
제어문
   1. if 문
       -형식 : 
          stmt0;
    if(조건문 ){
        //조건문 -->   논리형데이타가 반환되는 연산 
     //                   혹은 논리형상수
     stmt1;
     }else{
        stmt2;
     }
     stmt3;

     조건데이타가 true인경우  stmt0-->stmt1-->stmt3;
    조건데이타가 false인경우  stmt0-->stmt2-->stmt3;


*/

public class IfTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int x= 20, y= 30;

  System.out.println("stmt1");
  if (x > y){
   System.out.println(x+" > "+y);
  }
  else {
   System.out.println(x+" <= "+y);
   
  }
  System.out.println("stmt2");

  if (x > y){
   System.out.println(x+" > "+y);
  }
  System.out.println("stmt3");
  
  if (x == y)
   System.out.println(x+" == "+y);
   System.out.println("stmt4");
  
  if (x!=y)
   System.out.println(x+" != "+y);
  else
   System.out.println(x+"=="+y);

 }//end main

}//end class

//------ CH01. LogicalOperator - 논리 연산자 ------
import java.util.Scanner;

/*
  논리연산자
     - 형태:   ||(Logical OR) , && (Logical AND) ( |,& )
     - 좌우측의항이 논리형데이타이다.
           - 결과도 논리형데이타이다.
      ex> true || false, false && false
  */

public class LogicalOperator {

 private static Scanner sc;

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  boolean b1, b2;
  boolean result;
  
  b1 = true;
  b2 = false;
  
  result = b1 || b2;
  System.out.println("true || false = "+result);
  
  result = b1 && b2;
  System.out.println("true && false = "+result);
  
  b1 = false;
  
  result = b1 || b2;
  System.out.println("false || false = "+result);
  
  result = b1 && b2;
  System.out.println("flase && false = "+result);
  
  
  boolean flag = false;
  result = !flag;
  System.out.println("!false="+result);
  //수의 범위 체크
  
  int score = 0;
  boolean IsValid ;
  sc = new Scanner(System.in); //static으로 상단에서 지정
  
  System.out.println("***Input Your Score***");
  score = sc.nextInt();
  
  IsValid = (score >= 0) && (score <= 100); 
  System.out.println("1. score is "+IsValid);

  IsValid = ! ((score<0) || (score>100));
  System.out.println("2. score is "+IsValid);
 }
}

//------ CH01. RelationalOerator - 관계 연산자 ------
import java.util.Scanner;

/*
 관계(비교)연산
     - 형태:  >,<,>=,<=,==,!=
     - 관계연산의 결과값은 논리형 데이타이다(true,false)
*/

public class RelationalOerator {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int a = 10;
  int b = 20;
  
  boolean result;
  
  Scanner sc = new Scanner(System.in);
  
  a = sc.nextInt();
  
  result = a > b;
  System.out.println("10 > 20 =  "+result);
  result = a == b;
  System.out.println("10 == 20 =  "+result);
  result = a != b;
  System.out.println("10 != 20 =  "+result);
  
 }

}

//------ CH01. UnaryOperator - 단항 연산자 ------
/*
   단항연산자
       - 증가,감소연산자
      ex> i++ , i-- , ++i , --i 
            -자기자신의값을 정수 1만큼 증가시키거나 감소시키는
     연산자
  */
public class UnaryOperator {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  int i=0;
  
  System.out.println("i = "+ i);
  System.out.println("i = "+ i++);
  System.out.println("i = "+ ++i);
  
  
  
  int i1=4, j1=4;
  int result1, result2;
  result1 = ++i1;
  result2 = j1++;
  
  System.out.println("i1 = "+i1);
  System.out.println("j1 = "+j1);
  
  System.out.println("r1 = "+result1);
  System.out.println("r2 = "+result2);

 }

}

//------ CH01. VariableDeclare - 다양한 표현식 ------
public class VariableDeclare{
 public static void main(String[] args){
 //자바의 단문주석 
 /*
  자바의 장문주석1 
  자바의 장문주석2
 */ 
 
 /*
 자바변수의선언
  - 형태 :  타입 식별자(identifier);
                           ex> int  level;
 */
 //1.변수의 선언
 int score;
 int score1=8888;//선언 & 초기화
 int _score2=9999;
 int 스코어3=1000;
 /*
 int 2score;
 int my score;
 int super*score;
              int public;  
 */
 //2.변수의 초기화
 score = 7777; 
 System.out.println("score="+score);
 System.out.println("score1="+score1); 
 System.out.println("_score="+_score2); 
 System.out.println("스코어3="+스코어3); 
 
 }
}

//------ CH01. VariableTypes - 다양한 타입 ------
  //단문주석
  /*
  장문주석1
  장문주석2
  */
  
  /*
  변수의선언
                         - 의미:JVM 에게메모리를할당해달라고
                                요청하는작업
    - 형태:
          데이타타입 이름;
           ex> int number;

    - 변수식별자규직(클래스이름,변수이름,메쏘드이름)
      - 영문이나,한글로시작
      - 특수문자사용불가(_,$)
      - 키워드 사용금지
  */



public class VariableTypes {

 public static void main (String[] args){
  //1. 논리형(논리형상수 -> T,F는 그 자체 값 바꿀 수 X)
  boolean b1, b2;
  b1 = true;
  b2 = false; //java는 boolean값으로 0,1 지원X

  System.out.println ("b1 = "+b1);
  System.out.println ("b2 = "+b2);

  //2. 문자형
  char munja1, munja2, munja3, munja4;
  munja1 = 'a';
  munja2 = 'ㅁ';
  munja3 = '김';
  munja4 = 44608;

  int munja5 = '김';

  System.out.println ("munja1="+munja1);
  System.out.println ("munja2="+munja2);
  System.out.println ("munja3="+(int)munja3);
  System.out.println ("munja4="+munja4);
  System.out.println ("munja5="+munja5);

  int i=97;

  for (i=97; i<123; i++){
   System.out.print ((char)i+" ");
  }
  System.out.println ();


  //3. 숫자
  //3-1. 정수형 (정수형 상수)
  /********byte********/
  byte b = 100; //-128~127 (1byte)
   /*
    4바이트상수에 100을 넣고나서 byte에 넣더라도
    byte 범위 안에 감당할 수 있는 값이면 넣어준다.
    = 자동casting해준다.
   */
/*  byte by;
  int ii1 = 100;
  by = ii1; //possible loss of precision 이건 int->byte니까 무조건안됨.
*/
  /********shotr********/
  short s = 200; //-32768~32767 (2byte)

  /********int********/
  int i1; //(4byte)
  i1 = 2147483647; //int범위= -2147483648~2147483647
   /*
    i1 = 2147483648;
    error:integer number too large: 2147483648
   */

  /********long********/
  long l1 = 2147483648L; //(8byte) 
   /*
    long l1 = 2147483648;
    상수는 무조건 4byte로 잡힌 다음에 들어가기 때문에 
    long으로 선언해도 error, 그래서 숫자 뒤에L써줌
   */

  System.out.println ("i1 = "+i1);

  System.out.println ("l1 = "+l1);



  //3-2. 실수형 (실수형 상수 (0.2, 500.1, 45.12)기본 8byte double)
  float f1, f2;
  f1 = 3.141592f;
  System.out.println ("f1 = "+f1);

  double d1; 
  d1 = 0.012345678;
  System.out.println ("d1 = "+d1);

/********String Type (문자열형)********/
  String str1, str2;
  str1 = "열심히 살자";
  str2 = "될 놈은 된다";
  String str3 = str1+str2;
  System.out.println ("str3 = "+str3);
  
  
  /* tip: sysout + Ctrl+space =  System.out.println(); 
   * cf: Help - KeyAssist*/

 }

}

//------ CH01. YearTest - 윤년 출력 ------
import java.util.Scanner;

/*
 * 
 * ① 4로 나누어 떨어지는 해는 우선 윤년으로 하고
② 그 중에서 100으로 나누어 떨어지는 해는 평년으로 하며
③ 다만 400으로 나누어 떨어지는 해는 다시 윤년으로 정하였다

good
  String result="";
  
  if(year%4==0 && year%100!=0 || year%400==0) result="윤년";
  else result="평년";
  
  System.out.println(year+"년은 "+result+"입니다.");

 */
public class YearTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  int year;
  String youn_year = null;
  
  Scanner sc = new Scanner(System.in);
  year = sc.nextInt();
  
  if (year <= 0){
   System.out.println("년도 입력은 양수만 가능합니다.");
   return; //해당 경우에 하위 문장을 실행하지 않고 return
  }
  
  if (year%4 == 0){
   if (year%100 == 0){
    if (year%400 == 0){

     System.out.println(year+"년도는 윤년 입니다.");
    }
    else{ 
     System.out.println(year+"년도는 평년 입니다.");
    }
    
   }
   
   else{
    System.out.println(year+"년도는 윤년 입니다.");
   }
  }
  else{ 
   System.out.println(year+"년도는 평년 입니다.");
  }
   

 }

}