728x90
반응형
삼천리 자전거 회사에서 자전거 관리 프로그램을 요청했습니다.
1. 자전거 클래스를 적당한 영어로 정의하시오.
2. 여러분들이 관심있는 자전거 속성 2가지를 추출하여 private로 추가합니다.
3. 2가지 속성에 대한 getter, setter 함수를 클래스에 추가합니다.
4. 생성자 함수를 추가하시오.
5. 자전거 객체를 하나 생성한 후, 속성 정보를 출력하시오.
public class Samcheonri {
public static void main(String args[]) {
// Bicycle BicycleParts = new Bicycle();
Bicycle BicycleParts = new Bicycle("iron","plastic");
// BicycleParts.setChain("iron");
System.out.println(BicycleParts.getChain());
// BicycleParts.setPedal("plastic");
System.out.println(BicycleParts.getPedal());
}
}
class Bicycle {
private String chain;
void setChain(String chain) {
this.chain=chain;
}
String getChain() {
return this.chain;
}
private String pedal;
void setPedal(String pedal) {
this.pedal=pedal;
}
String getPedal() {
return this.pedal;
}
Bicycle(String chain, String pedal) {
this.chain=chain;
this.pedal=pedal;
}
}
전체 코드
public class Samcheonri {
public static void main(String args[]) {
// Bicycle BicycleParts = new Bicycle();
Bicycle BicycleParts = new Bicycle("iron","plastic");
// BicycleParts.setChain("iron");
System.out.println(BicycleParts.getChain());
// BicycleParts.setPedal("plastic");
System.out.println(BicycleParts.getPedal());
}
}
class Bicycle {
private String chain;
void setChain(String chain) {
this.chain=chain;
}
String getChain() {
return this.chain;
}
private String pedal;
void setPedal(String pedal) {
this.pedal=pedal;
}
String getPedal() {
return this.pedal;
}
Bicycle(String chain, String pedal) {
this.chain=chain;
this.pedal=pedal;
}
}
728x90
반응형
'즐거운프로그래밍' 카테고리의 다른 글
[자바] 클래스 메서드 오버로딩(overloading) (0) | 2023.10.17 |
---|---|
[자바] 클래스 상속 extends (0) | 2023.10.17 |
[자바] 노트패드++ String 클래스 (0) | 2023.10.16 |
[자바] 노트패드++ 다차원 배열 (1) | 2023.10.16 |
[자바] 노트패드++ 배열 (0) | 2023.10.16 |