Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

개발자 도전기

[JAVA] 입력과 출력 본문

개발공부/JAVA

[JAVA] 입력과 출력

jnnjnn 2024. 1. 25. 20:39

지난 예제에서 import 기능을 사용하여 IoT를 가상으로 만들어보는 실습을 했었는데

오늘은 그 예제에서 변수를 그때 그때 수정하는 것이 아닌, input을 활용하여 프로그램이 동작할 때마다 변수값을 새로 받아오는 방법에 대해 배웠다.

 

import javax.swing.JOptionPane;

import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Security;
import org.opentutorials.iot.Lighting;

public class OkHavaGoinHomeinput {

	public static void main(String[] args) {

		String id = JOptionPane.showInputDialog("Enter a ID");
		String bright = JOptionPane.showInputDialog("Enter a Bright level");
				
		// Elevator call
		Elevator myElevator = new Elevator(id);
		myElevator.callForUp(1);
		
		// Security off
		Security mySecurity = new Security(id);
		mySecurity.off();
		
		// Light on
		Lighting hallLamp = new Lighting(id + "/ Hall Lamp");
		hallLamp.on();
		
		Lighting floorLamp = new Lighting(id + "/ floor Lamp");
		floorLamp.on();
		
		DimmingLights moodLamp = new DimmingLights(id+ " moodLamp");
		moodLamp.setBright(Double.parseDouble(bright));
		moodLamp.on();
	}

}

 

swing의 기능인(?) JOptionPane.showInputDialog();를 사용하여 input을 입력하는 창을 띄우고

Double.parseDouble();을 활용하여 String 값을 double로 변환하는 것에 대해 배웠다.

 

이때 검색 엔진을 활용하여 내가 찾고자 하는 코드가 어떤 것인지 찾아보는 시연을 해주셨는데

내가 가진 지식이 완전하진 않더라도 검색을 통해 코드를 발전시킬 수 있다는 생각이 들었다.