Turtle Study: What I learned3

sung eon·2022년 6월 15일
0

스터디

목록 보기
6/13

Course.java

package com.sparta.turtle.prac;
.
public class Course {
    private String title;
    private String tutor;
    private int days;
.
    public Course(){}
.
    public Course(String title, String tutor, int days){
        this.title = title;
        this.tutor = tutor;
        this.days = days;
    }
.
    public void setTitle(String title) { //파라미터를 받.아.서 고쳐주는거니까 파라미터있음
        this.title = title;
    }
.
    public void setTutor(String tutor) {
        this.tutor = tutor;
    }
.
    public void setDays(int days) {
        this.days = days;
    }
.
    public String getTitle() { //받을건 없고 돌려주기만해서 파라미터 없음
        return this.title = title; //어던걸 돌려줄거냐? 우리가 받았던 this.---
    }
.
    public int getDays() {
        return this.days = days;
    }
.
    public String getTutor() {
        return this.tutor = tutor;
    }
}

Prac.java

package com.sparta.turtle.prac;
.
public class Prac {
    public static void main(String[] args){
        String title = "웹개발의 봄 스프링";
        String tutor = "남병관";
        int days = 35;
.
		//Getter, Setter후 표현방식 1.
        Course course1 = new Course(title, tutor, days);
        course1.setTitle(title);
        course1.setTutor(tutor);
        course1.setDays(days);
.
        System.out.println(course1.getTitle());
        System.out.println(course1.getTutor());
        System.out.println(course1.getDays());
 .      
 		////Getter, Setter후 표현방식 1.
        Course course2 = new Course("웹개발 종합반", "이범규", 35);
        System.out.println(course2.getTitle());
        System.out.println(course2.getTutor());
        System.out.println(course2.getDays());
    }
}
profile
코베베

0개의 댓글