S003_ContactsClass2 여러 Class 사용

Posted by PeEn
2019. 5. 14. 11:31 Programing/Java
package kr.ac.jj.java201562054;

import java.util.Scanner;

public class S003_ContactsClass2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Friend f = new Friend();

		f.Input();
		f.Print();

		Book b = new Book();
		b.BInput();
		b.BPrint();

	}

}

class Book {
	String title, author, publisher;// 제목 저자 출판사
	int price; // 가격
	Scanner scan = new Scanner(System.in);

	public void BInput() {
		System.out.printf("제목:");
		this.title = scan.next();

		System.out.printf("저자:");
		this.author = scan.next();

		System.out.printf("출판사:");
		this.publisher = scan.next();

		System.out.printf("가격:");
		this.price = scan.nextInt();

	}

	public void BPrint() {
		System.out.print("제목:" + this.title + "\n저자:" + author + "\n출판사:" + publisher + "\n가격:" + price);
	}

}

class Friend {
	String name;
	String phone;
	int speed_dial;

	public void Input() {
		Scanner scan = new Scanner(System.in);

		System.out.print("\n이름: ");
		this.name = scan.next();

		System.out.print("휴대폰: ");
		this.phone = scan.next();

		System.out.print("단축번호: ");
		this.speed_dial = scan.nextInt();
	}

	public void Print() {
		System.out.println("\n이름 : " + this.name + "\n휴대폰 : " + this.phone + "\n단축번호 : " + this.speed_dial);

	}
}