개발/부트캠프

본캠프 : 개인 과제(계산기 만들기) Getter, Setter 코드

EJ EJ 2025. 1. 13. 20:52

public class App {

public static void main(String[] args) {

// 연산 결과를 컬렉션에 저장하기
calculator1.setResultList(result);
// 연산 종료 후 저장된 전체 결과값 출력
System.out.println("전체 결과값: " + calculator1.getResultList());

 

 

public class Calculator {

private int result;
private ArrayList<Integer> resultList = new ArrayList<Integer>();
// 연산 결과를 컬렉션에 저장하기
public void setResultList(int result) {
    this.resultList.add(result);
}
// 연산 전체 결과값 불러오기
public ArrayList<Integer> getResultList() {
    return this.resultList;

 

 

*단축키 사용법

클래스 { } 안에서 command + N 이후에 command + A(전체 선택)을 누르면 해당 필드에 대한 게터와 세터를 자동으로 생성할 수 있다.

 

+) 변수명 변경 시에는 더블 클릭하여 오른쪽 Rename으로 변경을 해야 다른 줄에 적힌 해당 변수명도 일괄적으로 자동 변경된다.