본문 바로가기

Programming/자바

생활코딩 자바 리뉴얼 10. 입출력

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();

}

}