커뮤니티

고용노동부, 산업인력공단과 함께하는 강원도 유일한 기업중심 IT전문교육기관 ICT융합캠퍼스만의 특별한교육입니다.
공인 IT숙련기술인의 다양한 접근방법으로 전문가다운 실무교육을 받을 수 있습니다.

Category

교육강좌

언어 JAVA1 - 입력과 출력

페이지 정보

작성자 관리자 댓글 0건 조회 4,167회 작성일 20-06-01 17:01

본문

입력과 출력

수업소개

똑같은 결과를 출력하는 프로그램은 일회용입니다. 하지만 입력에 따라서 다른 출력 결과를 만들어주는 프로그램은 다양한 상황에서 힘을 발휘할 수 있습니다. 여기서는 재활용 가능한 프로그램을 만드는 방법을 살펴봅니다.

 

 

 

강의1

소스코드

변경사항

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
31
32
33
34
35
36
import javax.swing.JOptionPane;
import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;
public class OkJavaGoInHomeInput {
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+" / floorLamp");
floorLamp.on();
DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
moodLamp.setBright(Double.parseDouble(bright));
moodLamp.on();
}
}

 

 

 

강의2

이클립스 내에서 입력값(arguments)를 설정할 때 작은 따옴표로 동작하지 않으면 큰 따옴표를 이용해주세요. 
정정합니다.수업에서 표준적인 입력이라는 표현이 사용되고 있는데, 표준입력이라는 개념이 별도로 존재합니다. 따라서 이 수업에서 다루는 입력은 명령어로 실행되는 프로그램에 파라미터를 통해서 인자를 전달하는 방식이라고 표현해야 좀 더 정확합니다. 명령어로 실행되는 프로그램이 무엇인지는 뒤에서 더 정확하게 배우게 됩니다. 

소스코드

변경사항

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
31
32
33
34
35
import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;
public class OkJavaGoInHomeInput {
// paramter, 매개변수
public static void main(String[] args) {
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+" / floorLamp");
floorLamp.on();
DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
moodLamp.setBright(Double.parseDouble(bright));
moodLamp.on();
}
}

 

  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기

답변목록

등록된 답변이 없습니다.