💻 개인공부 💻/Java

회원가입 시스템(아이디 중복시 회원가입 불가능)

공대생 배기웅 2020. 1. 17. 18:08
반응형

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.*;
 
 
class Information{
    
    String id;
    String password;
    
    public Information(String id, String password){
        this.id=id;
        this.password=password;
    }
 
    
    
}
 
public class SavingInformation {
 
    private static String name;
    private static String id;
    private static String password;
    static HashMap<String, Information> map=new HashMap<String, Information>();
    
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        while(true) {
        System.out.println("회원가입을 원하시면 1을, "+"누적된 데이터를 보고 싶으시면 2를 누르세요");
        Scanner scan=new Scanner(System.in);
        int enter;
        enter=scan.nextInt();
        
        if(enter==1) {
            Entering();
            System.out.println("회원가입이 완료되었습니다");
 
            
        } else if(enter==2) {
            Set<String>name=map.keySet();
            Iterator<String>it=name.iterator();
        System.out.print("<<누적된 데이터>>\n");
        while(it.hasNext()) {
            String names=it.next();
            Information information=map.get(names);
            System.out.println(names+"|"+information.id+"|"+information.password);
        }
        }else 
            System.out.println("다시 입력하세요");
        
        }
        
    }
    
//==========================<<데이터 입력하는 메서드>>===================================    
    public static void Entering() {
        
        
        Scanner sc=new Scanner(System.in);
        
        System.out.println("<<성명을 입력하세요>>");
        name=sc.nextLine();
        
        
        while(true) {
        System.out.println("<<아이디를 입력하세요>>");
        id=sc.nextLine();
        boolean a=map.containsValue(map.get(id));
        
        if(a==true) {
            System.out.println("WARNING!!:이미 존재하는 아이디 입니다. 다른 아이디를 입력해주세요");
        }else 
            break;
        }
        
        System.out.println("<<비밀번호를 입력하세요>>");
        password=sc.nextLine();
        
        
}
}
 
//==========================<<데이터 입력하는 메서드>>===================================    
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

HashMap에 데이터를 입력하여 산출

728x90
반응형