본문 바로가기
java

회원관리 기능

by 헤르쯔44 2021. 10. 20.
728x90
반응형

1.회원관리 기능을 갖는 프로그램 만들어 보세요.
회원정보 : 아이디,비밀번호,이메일,전화번호
회원정보를 갖는 클래스를 만들고 ArrayList에 저장하고 아래의 기능을
작성해 보세요.

회원추가기능
회원검색기능(아이디로 검색하면 모든 정보 출력)
회원삭제기능(아이디를 입력하면 해당 정보 삭제) - remove메소드
회원수정기능(아이디를 입력받아 비밀번호,이메일,전화번호를 수정할 수 
있도록)- set메소드

==== 화면  ====
1.회원추가  2.회원검색 3.회원삭제   4.회원수정  5.종료
원하는 메뉴:1
[회원추가]
아이디:__

 

package test;


import java.util.Scanner;
import java.util.ArrayList;
import java.util.Iterator;
class Membership{
	private String id;
	private String pwd;
	private String email;
	private String phone;

	public Membership(){}
	public Membership(String id, String pwd, String email, String phone){
		this.id = id;
		this.pwd = pwd;
		this.email = email;
		this.phone = phone;
	}
	public String getId(){
		return id;
	}
	
	public String getPwd() {
		return pwd;
	}
	public String getEmail() {
		return email;
	}
	public String getPhone() {
		return phone;
	}
	public void input(){
		Scanner scan = new Scanner(System.in);
		System.out.print("아이디:");
		id = scan.next();
		System.out.print("비밀번호:");
		pwd = scan.next();
		System.out.print("이메일:");
		email = scan.next();
		System.out.print("전화번호:");
		phone = scan.next();
	}
	public void print(){
		System.out.println("*아이디:"+id);
		System.out.println("*비밀번호:"+pwd);
		System.out.println("*이메일:"+email);
		System.out.println("*전화번호:"+phone);
	}
}
class HW{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		ArrayList<Membership> list = new ArrayList<Membership>();
		String idInput;

		while(true){
			System.out.println("=============================================================================");
			System.out.println("1.회원추가   2.회원검색   3.회원삭제   4.회원수정   5.모든회원 출력   6.종료");
			System.out.print("원하는 메뉴:");
			int in = scan.nextInt();

			if(in == 1){
				System.out.println("[ 회원추가 ]");
				Membership mbPlus = new Membership();
				mbPlus.input();
				list.add(mbPlus);
			}else if(in ==2){
				System.out.println("[ 회원검색 ]");
				System.out.print("검색할 아이디입력:");
				idInput = scan.next();

				boolean find = false;
				for(int i = 0; i < list.size(); i++){
					Membership mbSearch = list.get(i);
					if(mbSearch.getId().equals(idInput)){
						mbSearch.print();
						find = true;
						break;
					}
				}
				if(!find){
					System.out.println("해당하는 아이디가 없습니다.");
				}
				
			}else if(in == 3){
				System.out.println("[ 회원삭제 ]");
				System.out.print("삭제할 아이디입력:");
				idInput = scan.next();
				
				boolean find = false;
				for(int i = 0; i < list.size(); i++){
					Membership mbRemove = list.get(i);
					if(mbRemove.getId().equals(idInput)){
						list.remove(i);
						System.out.println("해당 회원이 삭제되었습니다.");
						find = true;
						break;
					}
				}
				if(!find){
					System.out.println("해당하는 아이디가 없습니다.");
				}
			}else if(in == 4){
				System.out.println("[ 회원수정 ]");
				System.out.print("수정할 아이디입력:");
				idInput = scan.next();
				for(int i = 0; i < list.size(); i++){
					Membership mbModify = list.get(i);
					if(mbModify.getId().equals(idInput)){
						System.out.print("수정할 비밀번호입력:");
						String pwd = scan.next();
						System.out.print("수정할 이메일입력:");
						String email = scan.next();
						System.out.print("수정할 전화번호입력:");
						String phone = scan.next();
						Membership mbModify2 = new Membership(idInput, pwd, email, phone);
						list.set(i, mbModify2);
						break;
					}
				}
			}else if(in == 5){
				System.out.println("[ 모든 회원 출력 ]");
				Iterator<Membership> it = list.iterator();
				while(it.hasNext()){
					Membership mbs = it.next();
					mbs.print();
					System.out.println("---------------------");
				}
			}else if(in == 6){
				System.out.println("***종료합니다***");
				break;
			}
		}
	}
}
728x90
반응형

'java' 카테고리의 다른 글

FileReader/FileWriter  (0) 2021.10.20
HashMap/Calender  (0) 2021.10.20
[9/17] class ,생성자,메소드  (0) 2021.10.20
[JAVA-문법] 1. 출력,main메소드  (0) 2021.09.13
[JAVA-개념] 1. JAVA의 특징  (0) 2021.09.11