Project

JAVA(자바) - 휴대폰 매장 계약서 작성 시스템 만들기

코너(Corner) 2020. 11. 19.
반응형

자바 - 휴대폰 매장 계약서 작성 시스템 만들기

(미완성)

 

휴대폰 신규 회원을 가입하기 위한 프로그램을 구현 하였다.


 

처음 시작 시, 가입과 나가기를 선택 

1 . 개인 2. 개인 사업자 3. 외국인 선택

계약서에서 1. 개인을 택하면 (한국인 기준)

이름을 한국어로만 적을 수 있게 되었다.

주민번호를 작성하는데 양식은 yymmdd-1(남자)or2(여자) 까지만 입력 받는다.

명세서를 어떠한 방식으로 받을 것인지를 선택하는 것인데 특별한 기능은 없다.
e-mail을 선택하면 e-mail 주소를 적어야 하며, 모바일과 우편으로 받게되면 e-mail 입력 없이 넘어간다.

양식대로 입력이 끝나면 정상적으로 계약 내용이 확인된다.

시스템 종료 출력문 - 


소스 코드

Main - Class

package CellPhoneShop_ver1;
import java.util.Scanner;

// 핸드폰 매장 신규회원 클래스 생성, 
// 속성 기능을 구분해서 클래스 만들기
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Account ac = new Account();
		AccountMethod am = new AccountMethod();
		
		int act;
		while ( true ) {
			try {
			do {
				System.out.println("**Welcome to, Hogu Phone Shop**");
				System.out.println("1.Sign Up Contract | 2. EXIT.. ");
				System.out.println("--------------------------------");
				act = sc.nextInt();
			} while(act < 1 && act > 4);
			switch(act) {
			case 1: am.contractCategory(); break;
			case 2: am.endSystem(); 
				}
			
			}catch (Exception e) {
				System.out.println(e.toString());
			}
		}
		
		
	}

}

Account - Class // 계정의 주 객체의 속성들을 담고 있으며, private getter setter 이용 클래스

package CellPhoneShop_ver1;

public class Account {
	int customerCategory;	//고객 구분,
	int specification; // 1.이메일,2.모바일,3.우편
	boolean emailApply; // e-mail 명세서 신청 유/무
	boolean automaticPaymen; // 요금 자동 납부 유/무
	private String customerName,socialNumber; // 주민번호는 851213-2 까지만 입력

	private String email,contact,address; // email,연락처,주소
	private String modelName,modelSerial;//모델명, 일련번호 ex)삼성,LG -
	private int cashAdvance; // 선납
	int shippingPrice,purchasePrice;//출고가 구입가
	float discountRate;// 요금 할인율 백분율 %
	int priceDc; // 요금할인 
	
	public String getCustomerName() {return customerName;}
	public void setCustomerName(String customerName) {this.customerName = customerName;}
	public String getSocialNumber() {return socialNumber;	}
	public void setSocialNumber(String socialNumber) {this.socialNumber = socialNumber;	}
	public String getEmail() {return email;	}
	public void setEmail(String email) {this.email = email;}
	public String getContact() {return contact;}
	public void setContact(String contact) {this.contact = contact;}
	public String getAddress() {return address;}
	public void setAddress(String address) {this.address = address;}
	public String getModelName() {return modelName;	}
	public void setModelName(String modelName) {this.modelName = modelName;}
	public String getModelSerial() {return modelSerial;	}
	public void setModelSerial(String modelSerial) {this.modelSerial = modelSerial;	}
	public int getCashAdvance() {return cashAdvance;}
	public void setCashAdvance(int cashAdvance) {this.cashAdvance = cashAdvance;}

	public String toString() {
		String str = String.format("이름:%s\n주민번호:%s\n연락처:%s\n이메일:%s\n주소:%s\n구매 모델:%s\n모델 시리즈:%s\n", 
				customerName,socialNumber,contact,email,address,modelName,modelSerial);
		
		return str;
	}
	
	
}

AccountException - Class // 계정의 예외처리문을 보여줄 정규식 표현 정의 클래스

package CellPhoneShop_ver1;
import java.util.regex.Pattern;

public class AccountException {

	public void nameCheck(String name) throws AuthenException{
		boolean check = Pattern.matches("^[가-힣]*$",name);
		// 정규 표현식 regular 한글만 허용하기
		if(!check) {
			throw new AuthenException("이름은 한글로 적어야 합니다.");
		}
	}
	public void socialNumCheck(String number) throws AuthenException{
		boolean check = Pattern.matches("^(?:[0-9]{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[1,2][0-9]|3[0,1]))-[1-2]{1}$", number);
		if(!check) throw new AuthenException("주민번호는 ******-1or2로만 입력 가능합니다.");
		
	}
	public void emailCheck(String email) throws AuthenException {
		boolean check = Pattern.matches("^[A-Za-z0-9]+@(.+)$", email);
		if(!check) throw new AuthenException("email은 xxxx@yyyy.com 형식으로 입력하세요");
	}
	
	public void phoneCheck(String phone) throws AuthenException{
		boolean check = Pattern.matches("(\\d{3})-(\\d{3,4})-(\\d{4})",phone);
		if(!check) throw new AuthenException("전화번호 입력은[010-****-****]로 입력하세요.");
	}
	
}

AccountMethod - Class // 계정의 주 기능을 담고 있는 클래스

package CellPhoneShop_ver1;

import java.util.Scanner;

public class AccountMethod extends Account {
	Scanner sc = new Scanner (System.in);
	AccountException ae = new AccountException();
	Account acc = new Account();

//	private ArrayList contractList = new ArrayList<>();
	public AccountMethod () {
//		contractList = new ArrayList<Account>();
	} 
	// ---------------------함수 구현---
	public void contractCategory() throws AuthenException { // 신규회원의 가입 선택
		System.out.println("----Contract----");
		System.out.print("Check Plz > 1.individual | 2.individual Business | 3.Foreigner \n >");
		customerCategory = sc.nextInt();
		if(customerCategory == 1 ) {
			contractIndividual();
		} else if (customerCategory == 2 ) {
			contractBusiness();
		} else if (customerCategory == 3 ) {
			contractForeigner();
		}
	}
	public void contractIndividual() throws AuthenException {
		boolean name = true,socialNum = true,email=true,phone=true;

		try { 
			Account account = new Account(); 
			do {
				try {
					System.out.print("what your Name >");
					account.setCustomerName(sc.next());
					ae.nameCheck(account.getCustomerName());
					name = false;
				} catch (Exception e) {
					System.out.println(e.toString());
				}
			} while (name);
			do {
				try {
					System.out.print("your Social Security Number >");
					account.setSocialNumber(sc.next());
					ae.socialNumCheck(account.getSocialNumber());
					socialNum = false;
				} catch (Exception e) {
					System.out.println(e.toString());
				}
			} while (socialNum);

			do {
				try {
					System.out.print("what specifications do you want?"
							+ "\n |1. e-mail |2. mobile |3. post |\n >");
					specification = sc.nextInt();
					if ( specification == 1 ) {
						account.emailApply = true;
						System.out.print("e-mail Input >");
						account.setEmail(sc.next());
						ae.emailCheck(account.getEmail());
						email = false;
					} else if (specification == 2 ) {
						account.emailApply = false;
						account.setEmail("-Mobile- check");
						email=false;
					} else if ( specification == 3 ) {
						account.emailApply = false;
						account.setEmail("-Post- check");
						email=false;
					} else {
						System.out.println("재 입력 바람");
					} 
				} catch (Exception e) {
					System.out.println(e.toString());
				}
			}while (email);
			
				do {
					try {
						System.out.print("ur address >");
						account.setAddress(sc.next());
						System.out.print("Phone Model > ");
						account.setModelName(sc.next());
						System.out.print("Phone Serial Number > ");
						account.setModelSerial(sc.next());
						System.out.println("ex)010-1111-1111 \t 011-123-4567");
						System.out.print("Enter the phone number you want >");
						account.setContact(sc.next());
						phone = false;
					}catch (Exception e) {
						System.out.println(e.toString());
					}
				} while (phone);
					System.out.println("\n 휴대폰 계약을 축하드립니다! \n");
					System.out.println("[ 계약 내용 확인 ]");
					System.out.println(account.toString());
				} catch (Exception e) {
				System.out.println(e.toString());
			}
		}
		public void contractBusiness() {
			boolean name = true,socialNum = true,email=true,phone=true;
			try {
				Account account = new Account();
				do {
					try {
						System.out.println("name ? > ");
					}catch (Exception e) {
						System.out.println(e.toString());
					}
					
				} while ( name );
				
			} catch (Exception e) {
				System.out.println(e.toString());
			}
		}
		public void contractForeigner() {}
		public void endSystem() {
			System.out.println("\n\n\n\n---시스템 종료---\n\n");
			System.exit(0);
		}
		public int firstAmountBill() {return getCashAdvance();}
		public int monthAmountBill() {return getCashAdvance();}

	}

AuthenException - Class // 계약서 작성시 오류나는 예외처리문을 처리해주는 클래스

package CellPhoneShop_ver1;

public class AuthenException extends Exception{
	public AuthenException(String message) {
		super(message);
		}
	
}

 


반응형

댓글