ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 비행기 정보(생성자)
    코딩/java 2019. 2. 8. 02:04
    반응형

     

    public class Plane {

      String model;

    int id, capacity;

    public static int plane;

     

    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;

    plane++;

     }

     

    public static int getPlanes() { return plane;}

    }

     

     

     

    import java.util.Scanner;

    public class Practice_55 {

     

    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    Plane p1 = new Plane();

     

    System.out.println("제주행 비행기의 정보를 입력하세요.");

    System.out.print("식별번호: ");

    p1.setId(input.nextInt());

    System.out.print("모델: ");

    p1.setModel(input.next());

    System.out.print("승객수: ");

    p1.setCapacity(input.nextInt());

     

    System.out.print("제주행 비행기의 정보입니다.");

    System.out.print(p1.toString());

    System.out.println("현재까지 추가된 비행기는 모두 " + Plane.getPlanes() +"대 입니다.\n");

     

    System.out.println("서울행 비행기의 정보를 입력하세요.");

    System.out.print("식별번호: ");

    int id = input.nextInt();

    System.out.print("모델: ");

    String model = input.next();

    System.out.print("승객수: ");

    int capacity = input.nextInt();

     

    Plane p2 = new Plane(id, model, capacity);

     

    System.out.print("서울행 비행기의 정보입니다.");

    System.out.print(p2.toString());

    System.out.println("현재까지 추가된 비행기는 모두 " + Plane.getPlanes() +"대 입니다.\n");

     

    input.close();

    }

    }

     

     

    결과:

     

     

    반응형

    '코딩 > java' 카테고리의 다른 글

    영화 비교 (생성자)  (0) 2019.02.10
    날짜 비교(생성자)  (0) 2019.02.08
    은행계좌(생성자)  (0) 2019.02.08
    영화 정보 출력(생성자)  (0) 2019.01.07
    랜덤 숫자 200개 출력  (0) 2019.01.07
Designed by Tistory.