package CHAPTER05;

// 컴퓨터 부품을 나타내는 클래스
class ComputerPart {
	private String partName; // 부품명
	private String manufacturer; // 제조사
	private int price; // 가격

	// 기본 생성자 (기본 부품 설정)
	public ComputerPart() {
		// 다른 생성자 호출하여 기본값 설정
		this("Unknown Part", "Unknown Manufacturer", 0); 
		System.out.println("기본 부품이 생성되었습니다.");
	}

	// 매개변수 있는 생성자 (부품 정보를 받아 초기화)
	public ComputerPart(String partName, String manufacturer, int price) {
		this.partName = partName; // this를 사용하여 인스턴스 변수와 매개변수를 구분
		this.manufacturer = manufacturer;
		this.price = price;
		System.out.println("부품이 등록되었습니다: " + this.partName + ", 제조사: " + this.manufacturer + ", 가격: " + this.price + "원");
	}

	// 부품명 수정 (메서드 체이닝 지원)
	public ComputerPart setPartName(String partName) {
		this.partName = partName;
		return this; // 현재 객체(this) 반환 -> 메서드 체이닝 가능
	}

	// 제조사 수정 (메서드 체이닝 지원)
	public ComputerPart setManufacturer(String manufacturer) {
		this.manufacturer = manufacturer;
		return this; // 현재 객체 반환
	}

	// 가격 수정 (메서드 체이닝 지원)
	public ComputerPart setPrice(int price) {
		this.price = price;
		return this; // 현재 객체 반환
	}

	// 부품 정보 출력
	public void displayInfo() {
		System.out.println(
				"변경된 부품 정보 -> 부품명: " + this.partName + ", 제조사: " + this.manufacturer + ", 가격: " + this.price + "원");
	}
}

public class LAB01_ThisKeyword {
	public static void main(String[] args) {
		
		// 1. 기본 부품 생성
		System.out.println("컴퓨터 부품 생성 중...");
		ComputerPart cpu = new ComputerPart("CPU", "Intel", 300000); // 초기 정보 설정

		// 2. 메서드 체이닝을 활용한 정보 수정
		System.out.println("\n부품 정보 수정 (메서드 체이닝)...");
		cpu.setPartName("Ryzen 9") // 부품명 변경
		   .setManufacturer("AMD") // 제조사 변경
		   .setPrice(500000) // 가격 변경
		   .displayInfo(); // 변경된 정보 출력
	}
}