-
비행기 정보(생성자)코딩/java 2019. 1. 6. 23:26반응형
public class Plane {
String model;
int id, capacity;
public String toString() {
return "식별번호: " + id + "\n모델: " + model + "\n승객수: " + capacity +"\n";
}
public void setModel(String model) { this.model = model;}
public void setId(int id) {this.id = id;}
public void setCapacity(int capacity) {this.capacity = capacity;}
public Plane() {
this(0, "모름", 0);
}
public Plane(int i, String m, int c) {
this.id = i;
this.model = m;
this.capacity = c;
}
}
public class Practice_50 {
public static void main(String[] args) {
Plane p0 = new Plane();
Plane p1 = new Plane();
Plane p2 = new Plane(2464737, "보잉 747", 150);
p1.setId(1030615);
p1.setModel("보잉 737");
p1.setCapacity(75);
System.out.println("디폴트 비행기의 정보입니다.");
System.out.println(p0.toString());
System.out.println("제주행 비행기의 정보입니다.");
System.out.println(p1.toString());
System.out.println("서울행 비행기의 정보입니다.");
System.out.println(p2.toString());
}
}
결과:
반응형'코딩 > java' 카테고리의 다른 글
랜덤 숫자 200개 출력 (0) 2019.01.07 상자의 정보 (0) 2019.01.06 생일, 성년일 계산(설정자, 접근자) (1) 2019.01.06 은행 계좌(toString, 설정자, 접근자) (0) 2019.01.06 영화 정보 입력(toString) (0) 2019.01.06