728x90
package phonebook.var01;
//--------------------------------------------------------------------------
// class PhoneInfo
//--------------------------------------------------------------------------
class PhoneInfo{
String name;
String phoneNumber;
String birth;
public PhoneInfo(String name, String num, String birth) {
this.name = name;
phoneNumber = num;
this.birth = birth;
}
public PhoneInfo(String name, String num) {
this.name = name;
phoneNumber = num;
this.birth = null;
}
// 전화번호 정보를 보여주는 메서드
public void showInfo() {
System.out.println("==============================================");
System.out.println("이 름 : " + name);
System.out.println("전화번호 : " + phoneNumber);
if(birth != null)
System.out.println("생년월일 : " + birth);
}
} // End - class PhoneInfo
//--------------------------------------------------------------------------
// public class PhoneBookVer01
//--------------------------------------------------------------------------
public class PhoneBookVer01 {
public static void main(String[] args) {
PhoneInfo pInfo1 = new PhoneInfo("힝구", "010-1111-2222", "90년 09월 09일");
PhoneInfo pInfo2 = new PhoneInfo("밍구", "010-3333-7777");
pInfo1.showInfo();
pInfo2.showInfo();
}
} // End - public class PhoneBookVer01
package phonebook.var02;
import java.util.Scanner;
//--------------------------------------------------------------------------
//class PhoneInfo
//--------------------------------------------------------------------------
class PhoneInfo{
String name;
String phoneNumber;
String birth;
public PhoneInfo(String name, String num, String birth) {
this.name = name;
phoneNumber = num;
this.birth = birth;
}
public PhoneInfo(String name, String num) {
this.name = name;
phoneNumber = num;
this.birth = null;
}
// 전화번호 정보를 보여주는 메서드
public void showInfo() {
System.out.println("==============================================");
System.out.println("이 름 : " + name);
System.out.println("전화번호 : " + phoneNumber);
if(birth != null)
System.out.println("생년월일 : " + birth);
}
} // End - class PhoneInfo
//--------------------------------------------------------------------------
//public class PhoneBookVer02
//--------------------------------------------------------------------------
public class PhoneBookVer02 {
static Scanner keyboard = new Scanner(System.in);
public static void showMenu() {
System.out.println("========================================");
System.out.println("작업을 선택하십시오!");
System.out.println("0. 프로그램 종료");
System.out.println("1. 데이터입력");
System.out.println("선택 : ");
}
public static void inputData() {
System.out.println("========================================");
System.out.println("이름 : ");
String name = keyboard.nextLine();
System.out.println("전화번호 : ");
String phone = keyboard.nextLine();
System.out.println("생년월일 : ");
String birth = keyboard.nextLine();
PhoneInfo info = new PhoneInfo(name, phone, birth);
info.showInfo();
}
public static void main(String[] args) {
int choice = 0; // 작업 선택한 값을 저장할 변수
while(true) {
// 메뉴를 보여준다.
showMenu();
// 메뉴에서 작업할 것을 선택한다.
choice = keyboard.nextInt();
keyboard.nextLine();
switch(choice) {
case 1 : inputData(); // 전화번호 등록
break;
case 0 : // 프로그램 종료
return;
}
}
}
} // End - public class PhoneBookVer02
'Language > Java' 카테고리의 다른 글
[Java] 실습 fruitSalesVer02 (0) | 2022.08.08 |
---|---|
[Java] 실습 fruitSalesVer01 (0) | 2022.08.05 |
[Java] 실습 BlockExam (0) | 2022.08.05 |
[Java] 함수형 프로그래밍 (0) | 2022.08.05 |
[Java] 쓰레드 (Thread) (0) | 2022.08.05 |