실제로 만드는건 아니고 만드는 구조를 알아본다.
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;
public class OkJavaGoInHome {
public static void main(String[] args) {
String id = "JAVA APT 507";
//Elevater call
Elevator myElevater = new Elevator(id);
myElevater.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();
}
결과문
JAVA APT 507 -> Elevator callForUp stopFloor : 1
JAVA APT 507 -> Security off
JAVA APT 507 / Hall Lamp -> Lighting on
JAVA APT 507 / floor Lamp -> Lighting on
이미 있는 프로그래밍을 불러와 실행시키는 원리다
예를들어 Lighting을 쓰고 Ctlr + space를 누르면 import할수있는 Lighting파일이 나타나고 선택하여 작성중인 파일로 불러올수있다
이렇게 이미 작성된 프로그램을 불러와 새로운 변수로 정의하고
변수에게 적절한 명령을 입력하면 실행할수있다.
String id = JOptionPane.showInputDialog("Enter a ID");
String bright= JOptionPane.showInputDialog("Enter a Id");
DimmingLights moodLamp = new DimmingLights(id+" moolamp");
moodLamp.setBright(Double.parseDouble(bright));
moodLamp.on();
이클립스에서 run밑에 runconfigurations를 누르고 고정값을 주고싶은 class를 찾아 Aguments창을 눌러 “원하는고정값1” “원하는고정값2” “원하는고정값3”... 식으로 입력받을 고정값을 미리 설정할수있다.
이 고정값은
String id = args[0];
String bright= args[1];
이처럼 args[고정값숫자-1]을 입력하면 순서에 따라 고정값이 입력된다