TIL(Today I Learned)_230725

Aspyn ChoiΒ·2023λ…„ 7μ›” 25일
0

TIL

λͺ©λ‘ 보기
10/37

☝🏻였늘 배운 것

1. λ§€κ°œλ³€μˆ˜ μƒμ„±μž

- μ‚¬μš©λ˜λŠ” 기술, λ³€μˆ˜

: λ§€κ°œλ³€μˆ˜, Overloading(μ˜€λ²„λ‘œλ”©), this

- λ§€κ°œλ³€μˆ˜

: μƒμ„±μžλ‚˜ λ©”μ„œλ“œ 호좜 μ‹œ ()μ•ˆμ— μž‘μ„±λ˜μ–΄ μ „λ‹¬λ˜μ–΄μ§€λŠ” 값을 μ €μž₯ν•˜λŠ” λ³€μˆ˜
-> 전달받은 값을 μ €μž₯ν•˜κ³  μžˆλŠ” 맀개체 μ—­ν• μ˜ λ³€μˆ˜

- μ˜€λ²„λ‘œλ”©(Over loading)

: 클래슀 내에 λ™μΌν•œ μ΄λ¦„μ˜ λ©”μ„œλ“œ(μƒμ„±μž 포함)λ₯Ό μ—¬λŸ¬κ°œ μž‘μ„±ν•˜λŠ” 기법
: μžλ°”λŠ” 기본적으둜 ν•„λ“œλͺ…, μƒμ„±μžλͺ…, λ©”μ†Œλ“œλͺ…, λ³€μˆ˜λͺ…μ˜ 쀑볡을 ν—ˆμš©ν•˜μ§€μ•ŠμœΌλ‚˜
-> ν•˜λ‚˜μ˜ μ΄λ¦„μœΌλ‘œ μ—¬λŸ¬ κΈ°λŠ₯을 μˆ˜ν–‰ν•  수 있게 ν•˜λŠ” 것
: [μ˜€λ²„λ‘œλ”© 쑰건]
1) λ©”μ„œλ“œμ˜ 이름이 λ™μΌν•΄μ•Όν•œλ‹€
2) λ§€κ°œλ³€μˆ˜μ˜ 개수, νƒ€μž…, μˆœμ„œ 쀑 1κ°œλΌλ„ 달라야함. (λ³€μˆ˜λͺ…은 μ „ν˜€ 상관이 μ—†μŒ)

//	public User() {	} // κΈ°λ³Έ μƒμ„±μžκ°€ 이미 μž‘μ„±λ˜μ–΄μžˆμ–΄μ„œ 쀑볡
	public User(String userId) {} // λ§€κ°œλ³€μˆ˜μ˜ κ°œμˆ˜κ°€ 같은 μƒμ„±μžκ°€ μ—†μ–΄ μ˜€λ²„λ‘œλ”© 성립
	public User(int userAge) {} // λ§€κ°œλ³€μˆ˜μ˜ κ°œμˆ˜κ°€ κ°™μ§€λ§Œ, νƒ€μž…μ΄ 닀름. μ˜€λ²„λ‘œλ”© 성립
	public User(String userId, int userAge) {} // λ§€κ°œλ³€μˆ˜μ˜ κ°œμˆ˜κ°€ κ°™μ§€λ§Œ, ν•œκ°œμ˜ νƒ€μž…μ΄ 닀름. μ˜€λ²„λ‘œλ”© 성립
	public User(int userAge, String userId) {} // λ§€κ°œλ³€μˆ˜μ˜ 개수, νƒ€μž…μ΄ λͺ¨λ‘ λ™μΌν•˜μ§€λ§Œ μˆœμ„œκ°€ 닀름. μ˜€λ²„λ‘œλ”© 성립
	//public User(int userAge, String userName) {} // λ§€κ°œλ³€μˆ˜μ˜ κ°―μˆ˜μ™€, νƒ€μž…, μˆœμ„œκ°€ λͺ¨λ‘ κ°™μ•„ μ˜€λ²„λ‘œλ”© λΆˆκ°€. λ³€μˆ˜λͺ…은 μ‹ κ²½μ“°μ§€μ•ŠλŠ”λ‹€.
	

- this μ°Έμ‘°λ³€μˆ˜

: λ§€κ°œλ³€μˆ˜λ‘œ 전달받은 값을 ν•„λ“œμ— μ΄ˆκΈ°ν™”ν•˜λŠ” 것
: 객체가 자기 μžμ‹ μ„ μ°Έμ‘°ν•  수 μžˆλ„λ‘ ν•˜λŠ” λ³€μˆ˜
: λͺ¨λ“  객체의 내뢀에 thisκ°€ μˆ¨κ²¨μ Έμžˆλ‹€.
: μ™œ μ‚¬μš©ν•˜λŠ”κ°€?
-> ν•„λ“œλͺ…κ³Ό λ§€κ°œλ³€μˆ˜λͺ…이 같을 경우 이λ₯Ό κ΅¬λΆ„ν•˜κΈ° μœ„ν•΄μ„œ μ‚¬μš©ν•œλ‹€.

- this() μƒμ„±μž

: 같은 클래슀의 λ‹€λ₯Έ μƒμ„±μžλ₯Ό ν˜ΈμΆœν•  λ•Œ μ‚¬μš©
: μƒμ„±μž λ‚΄μ—μ„œ λ°˜λ“œμ‹œ 첫번째 쀄에 μž‘μ„±λ˜μ–΄μ•Όν•œλ‹€. μœ„μ— λ‹€λ₯Έ μ½”λ“œμ“°λ©΄ μ—λŸ¬
"Constructor call must be the first statement in a constructor"
: μ™œ μ‚¬μš©ν•˜λŠ”κ°€?
-> 쀑볡 μ½”λ“œ 제거, μ½”λ“œ 길이 κ°μ†Œ, μž¬μ‚¬μš©μ„± 증가
-> κ·ΈλŸ¬λ‚˜ 가독성이 μ’€ μ–΄λ €μš΄ κ²½μš°κ°€ 생길 μˆ˜μžˆμ–΄ 많이 μ‚¬μš©λ˜μ§€λŠ” μ•ŠμŒ

- λ§€κ°œλ³€μˆ˜ μƒμ„±μž 예제

public void ex3() {
		
		// μƒμ„±μž 확인 ν…ŒμŠ€νŠΈ
		
		// Student 객체λ₯Ό κΈ°λ³Έ μƒμ„±μžλ₯Ό μ΄μš©ν•΄ μƒμ„±ν•˜κ³  이λ₯Ό μ°Έμ‘°ν•˜λŠ” μ°Έμ‘°λ³€μˆ˜ s1에 λŒ€μž…ν•œ 것
		Student s1 = new Student();
					// κΈ°λ³Έ μƒμ„±μž
		
		// User κΈ°λ³Έ μƒμ„±μžλ₯Ό μ΄μš©ν•΄μ„œ 객체 생성
		User u1 = new User();
		
		// User 객체 ν•„λ“œ μ΄ˆκΈ°ν™” 확인
		System.out.println(u1.getUserId());
		System.out.println(u1.getUserPw());
		System.out.println(u1.getUserName());
		System.out.println(u1.getUserAge());
		System.out.println(u1.getUserGender());
		
		User u2 = new User();
		System.out.println(u2.getUserId());
		System.out.println(u2.getUserPw());
		System.out.println(u2.getUserName());
		System.out.println(u2.getUserAge());
		System.out.println(u2.getUserGender());	
		
		// 문제점 : u1이 μ°Έμ‘°ν•˜κ³ μžˆλŠ” User객체와
		// 			U2κ°€ μ°Έμ‘°ν•˜κ³ μžˆλŠ” User객체의 ν•„λ“œ 값이 λͺ¨λ‘ 동일함
		// 			μ™œ? 같은 κΈ°λ³Έ μƒμ„±μžλ‘œ User 객체λ₯Ό μƒμ„±ν–ˆκΈ° λ•Œλ¬Έμ—
		
		System.out.println("--------------------------------------");
		// 해결방법 1 : setterλ₯Ό μ΄μš©ν•΄μ„œ μƒˆλ‘œμš΄ κ°’ λŒ€μž…
		
		u2.setUserId("sefefs");
		u2.setUserPw("sdfwefsefwef");
		u2.setUserName("κΉ€μ˜ν¬");
		u2.setUserAge(19);
		u2.setUserGender('μ—¬');
		
		System.out.println(u2.getUserId());
		System.out.println(u2.getUserPw());
		System.out.println(u2.getUserName());
		System.out.println(u2.getUserAge());
		System.out.println(u2.getUserGender());	
		
		//해결방법 2 : λ§€κ°œλ³€μˆ˜ μƒμ„±μžλ₯Ό μ΄μš©ν•΄μ„œ
		//				객체가 생성될 λ•ŒλΆ€ν„° λ‹€λ₯Έ κ°’μœΌλ‘œ ν•„λ“œλ₯Ό μ΄ˆκΈ°ν™”
		
		User u3 = new User("test3", "password3");
				// μƒμ„±μž μˆ˜ν–‰ μ‹œ 전달할 값을 μž‘μ„±(μˆœμ„œλ₯Ό κΌ­ μ§€μΌœμ•Όν•¨)
		
		System.out.println(u3.getUserId());
		System.out.println(u3.getUserPw());
		
		
	}

	public void ex4() {//λ§€κ°œλ³€μˆ˜ μƒμ„±μž 예제
		
		User u1 = new User(); // κΈ°λ³Έμƒμ„±μž
		User u2 = new User("user02", "pass02") ;// λ§€κ°œλ³€μˆ˜ 2개 μƒμ„±μž
		User u3 = new User("user03", "pass03", "κΉ€μš©κΈ°", 30, '남');
		
		//λ§€κ°œλ³€μˆ˜ 5개 μƒμ„±μž
			
		System.out.printf("u1 : %s / %s / %s / %d / %c\n",
				u1.getUserId(), u1.getUserPw(), u1.getUserName(),
				u1.getUserAge(), u1.getUserGender()
			);
		
		System.out.printf("u2 : %s / %s / %s / %d / %c\n",
				u2.getUserId(), u2.getUserPw(), u2.getUserName(),
				u2.getUserAge(), u2.getUserGender()
			);

		System.out.printf("u3 : %s / %s / %s / %d / %c\n",
				u3.getUserId(), u3.getUserPw(), u3.getUserName(),
				u3.getUserAge(), u3.getUserGender()
			);

	}

2. λ©”μ†Œλ“œ

- λ©”μ†Œλ“œλž€?

: μˆ˜ν•™μ˜ ν•¨μˆ˜μ™€ λΉ„μŠ·ν•˜λ©° ν˜ΈμΆœμ„ 톡해 μ‚¬μš©
: 전달 값이 μ—†λŠ” μƒνƒœλ‘œ ν˜ΈμΆœμ„ ν•˜κ±°λ‚˜ μ–΄λ–€ 값을 μ „λ‹¬ν•˜μ—¬ ν˜ΈμΆœμ„ ν•˜λ©°, ν•¨μˆ˜ 내에 μž‘μ„±λœ μ—°μ‚° μˆ˜ν–‰
: κ·ΈλŸ¬λ‚˜, μˆ˜ν–‰ ν›„ λ°˜ν™˜ κ°’ / κ²°κ³Ό 값은 μžˆκ±°λ‚˜ 없을 수 있음
: ν•˜λ‚˜μ˜ λ©”μ†Œλ“œμ—λŠ” ν•˜λ‚˜μ˜ κΈ°λŠ₯만 μž‘μ„±ν•œλ‹€.

- λ©”μ†Œλ“œ μ ‘κ·Όμ œν•œμž

- λ©”μ†Œλ“œ μ˜ˆμ•½μ–΄

- λ©”μ†Œλ“œ λ°˜ν™˜ν˜•

- λ©”μ†Œλ“œ λ§€κ°œλ³€μˆ˜

- λ©”μ†Œλ“œ μ‚¬μš©ν•΄ 코딩해보기

  • MemberRun (런클래슀)
package edu.kh.oop.method.run;

import edu.kh.oop.method.model.service.MemberService;

public class MemberRun {

	public static void main(String[] args) {
// [μ ‘κ·Όμ œν•œμž][μ˜ˆμ•½μ–΄] λ°˜ν™˜ν˜• λ©”μ„œλ“œλͺ…([λ§€κ°œλ³€μˆ˜])
		
		MemberService service = new MemberService();
		// MemberService의 κΈ°λ³Έμƒμ„±μžκ°€ μž‘μ„±λ˜μ–΄μžˆμ§€μ•Šμ§€λ―Έγ…γ„΄
		// μ»΄νŒŒμΌλŸ¬κ°€ μ½”λ“œλ₯Ό λ²ˆμ—­ν•  λ•Œ
		// 클래슀 내뢀에 μƒμ„±μžκ°€ ν•˜λ‚˜λ„ μ—†λ‹€λ©΄
		// μžλ™μœΌλ‘œ κΈ°λ³Έ μƒμ„±μžλ₯Ό μΆ”κ°€ν•΄μ£ΌκΈ°λ•Œλ¬Έμ—
		// λ¬Έμ œμ—†μ΄ μ‚¬μš© κ°€λŠ₯!
		// λ§Œμ•½μ— μƒμ„±μžκ°€ ν•˜λ‚˜λΌλ„ 있으면 μžλ™μƒμ„± μ•ˆν•΄μ€€λ‹€!

		service.displayMenu(); // λ©”μ„œλ“œ 호좜
	}
}
  • Member (멀버 μ •μ˜ 클래슀)
package edu.kh.oop.method.model.vo;

public class Member {

	private String memberId;
	private String memberPw;
	private String memberName;
	private int memberAge;
	
	// κΈ°λ³Έμƒμ„±μž
	// κΈ°λ³Έ μƒμ„±μž κ·œμΉ™ : λ°˜ν™˜ν˜•μ΄ μ—†κ³ , ν΄λž˜μŠ€μ™€ 이름이 κ°™μ•„μ•Όν•œλ‹€.
	public Member() {}
	
	// λ§€κ°œλ³€μˆ˜ μƒμ„±μž(ν•„λ“œ μ΄ˆκΈ°ν™”)
	// μ˜€λ²„λ‘œλ”© 적용(λ§€κ°œλ³€μˆ˜μ˜ κ°œμˆ˜κ°€ 닀름)
	public Member(String memberId, String memberPw, String memberName, int memberAge) {
		
		// λ§€κ°œλ³€μˆ˜λ‘œ 전달받은 값을 ν•„λ“œλ‘œ λŒ€μž…μ‹œν‚€κΈ°.
		this.memberId = memberId;
		this.memberPw = memberPw;
		this.memberName = memberName;
		this.memberAge = memberAge;
		
	}

	
	// λ©”μ„œλ“œ (getter/setter 포함)
	public String getMemberId() {
		return memberId;
	}

	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}

	public String getMemberPw() {
		return memberPw;
	}

	public void setMemberPw(String memberPw) {
		this.memberPw = memberPw;
	}

	public String getMemberName() {
		return memberName;
	}

	public void setMemberName(String memberName) {
		this.memberName = memberName;
	}

	public int getMemberAge() {
		return memberAge;
	}

	public void setMemberAge(int memberAge) {
		this.memberAge = memberAge;
	}
}
  • MemberService (μ‹€ν–‰ν•  μ½”λ”©μž‘μ„±ν•˜λŠ” 클래슀)
package edu.kh.oop.method.model.service;

import java.util.Scanner;

import edu.kh.oop.method.model.vo.Member;

public class MemberService {
	
	// 속성(ν•„λ“œ) -> μΊ‘μŠν™”μ›μΉ™μ— μ˜ν•΄ private으둜 μž‘μ„±
	private Scanner sc = new Scanner(System.in);
	private Member memberInfo = null; // κ°€μž…ν•œ νšŒμ›μ˜ 정보λ₯Ό μ €μž₯ν•œ λ³€μˆ˜
	private Member loginMember = null; // λ‘œκ·ΈμΈν•œ νšŒμ›μ˜ 정보λ₯Ό μ €μž₯ν•  λ³€μˆ˜
	
	// κΈ°λŠ₯(μƒμ„±μž+λ©”μ„œλ“œ)
	
	// 메뉴화면 좜λ ₯ κΈ°λŠ₯
	public void displayMenu() {
		// λ°˜ν™˜ν˜•
		
		int menuNum = 0; // 메뉴 μ„ νƒμš© λ³€μˆ˜
		
		// 무쑰건 ν•œλ²ˆμ€ 반볡 -> do  while
		do {
			System.out.println("====νšŒμ› 정보 관리 ν”„λ‘œκ·Έλž¨====");
			System.out.println("1. νšŒμ›κ°€μž…");
			System.out.println("2. 둜그인");
			System.out.println("3. νšŒμ›μ •λ³΄ 쑰회");
			System.out.println("4. νšŒμ›μ •λ³΄ μˆ˜μ •");
			System.out.println("0. ν”„λ‘œκ·Έλž¨ μ’…λ£Œ");
			
			System.out.print("메뉴 μž…λ ₯ : ");
			menuNum = sc.nextInt();
			sc.nextLine(); // μž…λ ₯ 버퍼에 남은 κ°œν–‰λ¬Έμž 제거용
			
			switch(menuNum) {
			case 1 : System.out.println(signup()); break;
			case 2 : System.out.println(login()); break;
			case 3 : System.out.println(selectMember()); break;
			case 4 : 
				int result = updateMember();
				if(result == -1) {
					System.out.println("둜그인 ν›„ μ΄μš©ν•΄μ£Όμ„Έμš”.");
				}else if(result ==0) {
					System.out.println("νšŒμ›μ •λ³΄ μˆ˜μ • μ‹€νŒ¨(λΉ„λ°€λ²ˆν˜Έ 뢈일치");
				}else {
					System.out.println("νšŒμ›μ •λ³΄κ°€ μˆ˜μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
				}
				; break;
			case 0 : System.out.println("ν”„λ‘œκ·Έλž¨ μ’…λ£Œ..."); break;
			default : System.out.println("잘λͺ»μž…λ ₯ν•˜μ…¨μŠ΅λ‹ˆλ‹€. λ‹€μ‹œ μž…λ ₯ν•΄μ£Όμ„Έμš”");
			}
			
			
		}while(menuNum != 0); // menuNum이 0이면 반볡 μ’…λ£Œ
	}
	
	// νšŒμ›κ°€μž… κΈ°λŠ₯
	public String signup() {
		//(λ°˜ν™˜ν˜•)
		// ν•΄λ‹Ή λ©”μ†Œλ“œκ°€ λλ‚˜κ³  ν˜ΈμΆœν•œ 곳으둜 λŒμ•„κ°ˆλ•Œ
		// String μžλ£Œν˜• 값을 가지고 λŒμ•„κ°„λ‹€λŠ”λœ»
		
		System.out.println("\n======νšŒμ›κ°€μž…======");
		
		System.out.print("아이디 : ");
		String memberId = sc.next();
		
		System.out.print("λΉ„λ°€λ²ˆν˜Έ : ");
		String memberPw = sc.next();
		
		System.out.print("λΉ„λ°€λ²ˆν˜Έ 확인 : ");
		String memberPw2 = sc.next();
		
		System.out.print("이름 : ");
		String memberName = sc.next();
		
		System.out.print("λ‚˜μ΄ : ");
		int memberAge = sc.nextInt();
		
		// λΉ„λ°€λ²ˆν˜Έ, λΉ„λ°€λ²ˆν˜Έ 확인이 μΌμΉ˜ν•˜λ©΄ νšŒμ›κ°€μž…
		// μΌμΉ˜ν•˜μ§€μ•ŠμœΌλ©΄ νšŒμ›κ°€μž…μ‹€νŒ¨
		
		if(memberPw.equals(memberPw2)) {// μΌμΉ˜ν•˜λŠ”κ²½μš°
			
			// μž…λ ₯받은 정보λ₯Ό μ΄μš©ν•΄μ„œ Member 객체 μƒμ„±ν•œ ν›„
			// μƒμ„±λœ 객체의 μ£Όμ†Œλ₯Ό ν•„λ“œμ— μžˆλŠ” memberInfo에 λŒ€μž…
			memberInfo = new Member(memberId, memberPw, memberName, memberAge);
			
			return "νšŒμ›κ°€μž… 성곡!!";
			/* 좜λ ₯ ꡬ문 λ©”μ†Œλ“œλ₯Ό ν˜ΈμΆœν•œ κ³³μ—μ„œ ν•œλ²ˆλ§Œ μ“°κ³ ,
			 * return을 μ΄μš©ν•΄ 전달할 값을 μž‘μ„±
			 */
			// return : ν˜„μž¬ λ©”μ†Œλ“œλ₯Ό μ’…λ£Œν•˜κ³  ν˜ΈμΆœν•œ 곳으둜 λŒμ•„κ°
			// return κ°’; : ν˜ΈμΆœν•œ 곳으둜 λŒμ•„κ°ˆ λ•Œ 값을 가지고 λŒμ•„κ°.
			
		}else { // μΌμΉ˜ν•˜μ§€ μ•ŠλŠ” 경우
			
			return "νšŒμ›κ°€μž… μ‹€νŒ¨!! (λΉ„λ°€λ²ˆν˜Έ 뢈일치)";
		}	
	}
	
	// 둜그인 κΈ°λŠ₯
	public String login() {
		
		System.out.println("\n*********둜그인*********");
		
		// νšŒμ›κ°€μž…μ„ ν–ˆλŠ”μ§€ λΆ€ν„° 확인
		// == memberInfoκ°€ 객체λ₯Ό μ°Έμ‘°ν•˜κ³  μžˆλŠ”μ§€ 확인
		
		 if(memberInfo == null) { // νšŒμ›κ°€μž…μ„ λ¨Όμ € μ•ˆν•œ 경우
			 // null : 아무것도 μ°Έμ‘°ν•˜κ³ μžˆμ§€ μ•ŠμŒ
			 return "νšŒμ› κ°€μž…λΆ€ν„° μ§„ν–‰ν•΄μ£Όμ„Έμš”.";
		 }
		 
		 System.out.print("아이디 μž…λ ₯ : ");
		 String memberId = sc.next();
		 System.out.print("λΉ„λ°€λ²ˆν˜Έ μž…λ ₯ : ");
		 String memberPw = sc.next();
		 
		 // νšŒμ›κ°€μž… μ •λ³΄μ—μ„œ
		 // μ €μž₯된 아이디, λΉ„λ°€λ²ˆν˜Έ == μž…λ ₯된 아이디, λΉ„λ°€λ²ˆν˜Έκ°€ κ°™μœΌλ©΄ "둜그인 성곡"
		 // μΌμΉ˜ν•˜μ§€ μ•ŠμœΌλ©΄ "아이디 λ˜λŠ” λΉ„λ°€λ²ˆν˜Έκ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."
		 
		 // 아이디, λΉ„λ°€λ²ˆν˜Έκ°€ λͺ¨λ‘ μΌμΉ˜ν•  경우
		 if(memberInfo.getMemberId().equals(memberId) && memberInfo.getMemberPw().equals(memberPw)) {
			 // μž…λ ₯받은 memberId와 
			 // memberInfoν•„λ“œμ—μ„œ 참쑰쀑인 λ©€λ²„κ°μ²΄μ˜ memberIdκ°€ 같은지 확인
			 loginMember = memberInfo;
			 //μ°Έμ‘°ν˜•    =  Member 객체 μ£Όμ†Œ (얕은 볡사)
			 // νšŒμ›κ°€μž…μ •λ³΄λ₯Ό loginMember에 λŒ€μž…ν•˜μ—¬
			 // μ–΄λ–€ νšŒμ›μ΄ λ‘œκ·ΈμΈν–ˆλŠ”μ§€λ₯Ό ꡬ뢄할 수 μžˆκ²Œν•¨.
			 
			 return loginMember.getMemberName() + "λ‹˜ ν™˜μ˜ν•©λ‹ˆλ‹€!";
			 
		 }else {
			 
			 return "아이디 λ˜λŠ” λΉ„λ°€λ²ˆν˜Έκ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.";
		 }
	}
	
	// νšŒμ›μ •λ³΄ 쑰회 κΈ°λŠ₯
	public String selectMember() {
		
		System.out.println("\n******νšŒμ› 정보 쑰회******");
		
		// 1) 둜그인 μ—¬λΆ€ 확인
		// 둜그인 μ•ˆν–ˆμ„ λ•ŒλŠ” "둜그인 ν›„ μ΄μš©ν•΄μ£Όμ„Έμš”" λ°˜ν™˜
		
		// 2) 둜그인이 λ˜μ–΄μžˆλŠ” 경우
		// νšŒμ›μ •λ³΄λ₯Ό 좜λ ₯ν•  λ¬Έμžμ—΄μ„ λ§Œλ“€μ–΄μ„œ λ°˜ν™˜
		// 단, λΉ„λ°€λ²ˆν˜ΈλŠ” μ œμ™Έ
		
		// 이름 : 홍길동
		// 아이디 : user01
		// λ‚˜μ΄ : 25μ„Έ
		
		if(loginMember == null) {
			return "둜그인 ν›„ μ΄μš©ν•΄μ£Όμ„Έμš”";
		}
		
		String str = "이름 : " + loginMember.getMemberName();
		str += "\n아이디 : " + loginMember.getMemberId();
		str += "\nλ‚˜μ΄ : " + loginMember.getMemberAge() + "μ„Έ";
				
		return str;
		
	}
	
	// νšŒμ›μ •λ³΄ μˆ˜μ • κΈ°λŠ₯
	public int updateMember() {
		
		System.out.println("\n*********νšŒμ› 정보 μˆ˜μ •*********");
		
		// 1. 둜그인 μ—¬λΆ€ νŒλ³„
		// λ‘œκ·ΈμΈλ˜μ–΄μžˆμ§€ μ•ŠμœΌλ©΄ -1 λ°˜ν™˜
		
		// 2. 둜그인이 λ˜μ–΄μžˆμ„ λ•Œ
		// 2-1) μˆ˜μ •ν•  νšŒμ›μ •λ³΄ μž…λ ₯λ°›κΈ°(이름,λ‚˜μ΄)
		
		// 2-2) λΉ„λ°€λ²ˆν˜Έλ₯Ό μž…λ ₯λ°›μ•„μ„œ λ‘œκ·ΈμΈν•œ νšŒμ›μ˜ λΉ„λ°€λ²ˆν˜Έμ™€ μΌμΉ˜ν•˜λŠ”μ§€ 확인
		
		// -> λΉ„λ°€λ²ˆν˜Έκ°€ 같을 경우
		// 		λ‘œκ·ΈμΈν•œ νšŒμ›μ˜ 이름, λ‚˜μ΄ 정보λ₯Ό μž…λ ₯받은 κ°’μœΌλ‘œ λ³€κ²½ ν›„ 1 λ°˜ν™˜
		
		// -> λΉ„λ°€λ²ˆν˜Έκ°€ λ‹€λ₯Ό 경우 0 λ°˜ν™˜
		
		if(loginMember == null) {
			return -1;
		}
		
		System.out.print("μˆ˜μ •ν•  이름을 μž…λ ₯ν•΄μ£Όμ„Έμš” : ");
		String memberName = sc.next();
		System.out.print("μˆ˜μ •ν•  λ‚˜μ΄λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” : ");
		int memberAge = sc.nextInt();
		System.out.print("λΉ„λ°€λ²ˆν˜Έλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”. : ");
		String memberPw = sc.next();
		
		if(memberPw.equals(loginMember.getMemberPw())) {
			
			loginMember.setMemberName(memberName);
			loginMember.setMemberAge(memberAge);
			return 1;
		}else {
			return 0;
		}
	}
}

0개의 λŒ“κΈ€