JAVA1

입력과 출력

수업소개

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

 

 

 

강의1

소스코드

변경사항

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

소스코드

변경사항

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

	}

}

 

댓글

댓글 본문
버전 관리
egoing
현재 버전
선택 버전
graphittie 자세히 보기