21.06.03 - 생활코딩 JAVA 공부

·2021년 6월 28일
0

생활코딩JAVA

목록 보기
3/12

1. 이클립스 디버거 사용법

  • 브레이크 포인터라고 부름
  • 프로그램 실행을 멈추고 싶을 때, 멈추고 싶은 부분에서 더블클릭하면 숫자 옆에 점이 생김.
  • 벌레 모양 클릭하면 디버거 모드로 화면 구성이 바뀜.

  • 디버거를 이용하면 코드 한 줄씩 실행시킬 수 있음. (Step Over 버튼)

  • 문제가 있거나 코드를 분석하고 싶을 때 디버거 이용.

2. 입력과 출력 (arguments & parameter)

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"); 
		// 팝업창에 내가 입력하는 ID가 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)); // bright는 더블로 입력되어야 하는데 string으로 입력해서 빨간줄이 뜸.구글링으로 string을 더블로 변환(?)해주는 코드 넣기.
		moodLamp.on();
		
	}

}

import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;


public class OkJavaGoinHomeInput2 {

	
	// args = parameter(매개변수) = arguments에서 입력한 "Java APT 507" "15.0"
	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();
		
	}

}
  • Run Configurations > Java Application > 인자를 설정하려는 파일 선택 > Arguments > Program arguments 안에 큰따옴표 사용해서 args 파라미터 값 입력 ("Seoul APT 507" "45.0") / 상단에 Name 옆에 입력 시에는 작은 따옴표로 입력해야 됨(버전따라 다른 듯) > Apply > Run

  • 기존의 argument 값이 아닌 다른 값을 넣고 테스트하고 싶으면 파일명 우측 클릭 > Duplicate

  • String id = args[0]; / String bright = args[1];  값이 여러 개일 때, 숫자로 순서를 정해준다.

0개의 댓글