코딩/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());

}

}

 

 

결과:

 

 

반응형