https://www.youtube.com/watch?v=-xllzUahaFQ&list=PLuHgQVnccGMAIluRRVsC1e79ri-dwnBmR&index=27
입출력값
지속적으로 변수 바꿀 때 편리
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 okJavagoinhomeinput {
public static void main(String[] args) {
String id = JOptionPane.showInputDialog("Enter an 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)); //string->souble 형변환
moodLamp.on();
}
}
arguments & parameter
argument : 인자
parameter : 매개변수
run 버튼 화살표 -> run configurations -> program arguments에 인자 추가 (''로 덩어리 만들기)
-> 인자들은 main(String[] args) 의 args로 들어가게 됨
import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Security;
import org.opentutorials.iot.Lighting;
public class okJavagoinhomeinput {
public static void main(String[] args) { //args : 매개변수(parameter)
String id = args[0];
String bright = args[1];
//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();
}
}
'Programming > 자바' 카테고리의 다른 글
생활코딩 자바 리뉴얼 12. 자바 문서 보기 (0) | 2022.02.23 |
---|---|
생활코딩 자바 11. 직접 컴파일 & 실행 (0) | 2022.02.22 |
생활코딩 자바 리뉴얼 9. 디버거 (0) | 2022.02.22 |
생활코딩 자바 리뉴얼 8. 프로그래밍 (0) | 2022.02.22 |
생활코딩 자바 리뉴얼 7. 변수 (0) | 2022.02.22 |