package day8;
import java.util.Scanner;
public class Util {
// 숫자 체크 메소드
public int numberCheck() {
int result;
Scanner sc = new Scanner(System.in);
while (true) {
if (sc.hasNextInt()) { // 입력한 값이 숫자면
result = sc.nextInt();
break;
} else {
System.out.print("숫자만 입력>");
sc.nextLine();
}
}
return result; // 입력한 값을 result에 저장
}
public int numberCheck1(String str) {
int result;
Scanner sc = new Scanner(System.in);
while (true) {
if (sc.hasNextInt()) { // 입력한 값이 숫자면
result = sc.nextInt();
break;
} else {
System.out.print(str + "는 숫자만 입력>");
sc.nextLine();
}
}
return result; // 입력한 값을 result에 저장
}
// str는 i자 이내 체크 함수
public String lengthCheck(String str, int maxLength) {
Scanner sc = new Scanner(System.in);
System.out.print(str+"입력 >");
String result;
result = sc.next();
while (true) {
if (result.length() <= maxLength) {
break;
} else {
System.out.println(str + "(은)는 " + maxLength + "자리 이내로 입력해주세요");
result = sc.next();
}
}
return result;
}
}
package day8;
import java.util.List;
import java.util.Scanner;
public class Util2 {
Scanner sc = new Scanner(System.in);
//숫자체크
public int numCheck() {
int result;
while(true) {
if(sc.hasNextInt()) {
result = sc.nextInt();
break;
}else {
System.out.print("숫자만 입력> ");
sc.nextLine();
}
}
return result;
}
// 아이디 길이체크 메소드
public String lengCheck(int max) {
String result;
while(true) {
result = sc.next();
if(result.length() > max) {
System.out.print("길이는 최대 "+max+"까지> ");
}else {
break;
}
}
return result;
}
// 아이디 중복체크 메소드
public String duCheck(List<User2> list) {
String result;
while(true) {
result = sc.next();
boolean find = false;
for(User2 u : list) {
if(u.getId().equals(result)) {
System.out.print("중복된 아이디입니다 다시입력> ");
find = true;
break;
}
}
if(!find) {
break;
}
}
return result;
}
}
각각 util , util2 메소드로 로그인 시스템에 쓸 메소드를 만들어보았다.
'Java > Java icia 8일차' 카테고리의 다른 글
로그인시스템 배운것들 추가해서 프로그램만들기 (0) | 2023.03.03 |
---|---|
멤버시스템 만들기( 필드,생성자,메소드를 이용) (0) | 2023.03.03 |
for문의 향상된,개선된 for문 (0) | 2023.03.03 |
ArrayList (0) | 2023.03.03 |
메소드를 이용해 유틸리티 만들기 (0) | 2023.03.03 |