
public class PhoneInfo
{
private String name;
private String phone;
private String birth;
public PhoneInfo(String name, String phone, String birth)
{
this.name = name;
this.phone = phone;
this.birth = birth;
}
public void showPhoneInfo()
{
System.out.println("이름 : " + name);
System.out.println("전화번호 : " + phone);
System.out.println("생년월일 : " + birth);
}
}
import java.util.Scanner;
public class PhoneInfoMain
{
public static void main(String[] args)
{
PhoneInfo info = null;
Scanner sc = new Scanner(System.in);
int menu = 0;
String name = null, phone = null, birth = null;
while(true)
{
System.out.println("선택하세요.");
System.out.println("1. 데이터 입력");
System.out.println("2. 프로그램 종료");
System.out.print("선택 : ");
menu = sc.nextInt(); // 1 엔터
sc.nextLine(); // 버퍼에 있는 엔터키 값을 없앤다.
switch(menu)
{
case 1:
System.out.print("이름 : ");
name = sc.nextLine();
System.out.print("전화번호 : ");
phone = sc.nextLine();
System.out.print("생년월일 : ");
birth = sc.nextLine();
info = new PhoneInfo(name, phone, birth);
Systme.out.println("입력이 완료되었습니다.");
System.out.println("입력된 정보 출력 ...");
info.showPhoneInfo();
break;
case 2:
System.out.println("프로그램을 종료합니다.");
return;
default:
System.out.println("잘못입력하셨습니다.");
}
}
}
}