package CHAP11;

//파일 다운로드를 시뮬레이션하는 스레드 클래스
class FileDownloader extends Thread {
	private String fileName; // 다운로드할 파일 이름

	// 생성자: 파일 이름을 전달받아 저장
	public FileDownloader(String fileName) {
		this.fileName = fileName;
	}

	// 스레드 실행 시 호출되는 메서드
	public void run() {
		System.out.println(fileName + " 다운로드 시작...");

		// 다운로드 진행률 1% ~ 100% 출력
		for (int i = 1; i <= 100; i++) {
			// 진행률 출력 (줄 바꿈 없이 덮어쓰기)
			System.out.print("\r[" + fileName + "] 진행률: " + i + "%");

			try {
				Thread.sleep(50); // 0.05초 대기 (총 5초)
			} catch (InterruptedException e) {
				break; // 인터럽트 발생 시 종료
			}
		}
		System.out.println("\n" + fileName + " 다운로드 완료!");
	}
}
public class LAB02_DownloadSimulator {
	public static void main(String[] args) {
		// 파일 다운로드 스레드 시작
		new FileDownloader("LectureNotes.pdf").start();
	}
}

