2023.06.07.수.TIL

heeh·2023년 6월 7일

TIL

목록 보기
16/82
post-thumbnail

팀프로젝트2 고객 회원가입, 로그인

회원가입

 System.out.println("이름: ");
    String name = scanner.nextLine();
    //String name = consoleUtil.getValueOf("이름");

    String phoneNumber = null;
    System.out.print("전화번호: ");
    phoneNumber = scanner.nextLine();
    //String phoneNumber = consoleUtil.getValueOf("전화번호");

    if (customerService.findOne(phoneNumber) != null) {
        System.out.println("이미 등록된 사용자입니다. 다시 시도해주세요.");
        return;
    }

    System.out.print("비밀번호: ");
    String password = scanner.nextLine();

    //String password = consoleUtil.getValueOf("비밀번호");

    System.out.print("소지금: ");
    int money = Integer.parseInt(scanner.nextLine());
    //int money = Integer.parseInt(consoleUtil.getValueOf("소지금"));

    // 고객의 이름, 전화번호, 비밀번호 입력하면서 회원가입 진행
    // nextLine 문장 다음으로 넘어감
    // Customer의 name, phoneNumber, password -> private으로 지정, this. 생성자, return 반환해주기

    Customer customer = new Customer();
    CustomerService.();

    System.out.println("가입이 완료됐습니다!");
}

Customer customer = new Customer();
CustomerService.();
공란으로 남겨두는.... 모르겠다....

package service;

   import entity.Customer;

   import java.util.HashMap;

   public class CustomerService {
   static HashMap<String, Customer> customers;  // 전화번호를 key값으로 함

   public CustomerService(){
    this.customers = new HashMap<>();
}

    //    public Customer findOne(String phoneNumber){ // String phoneNumber에서 찾는다..?
   //        Customer customer = null; // 값을 초기화하고
  //        return customer; // 반환한다...인가요...
 //    }

public void CustomerService(Customer customer) { this.customers.put(customer.getPhoneNumber(), customer); }


public static Customer findOne(String phoneNumber) {
    return this.customers.get(phoneNumber);
    }
}
  • public void CustomerService(Customer customer) { this.customers.put(customer.getPhoneNumber(), customer); }

  • public static Customer findOne(String phoneNumber) {
    return this.customers.get(phoneNumber);}

를 추가했는데...
저장하고 담아주는 것이 필요한데, 커스텀서비스랑 계속 안맞고 오류뜸...ㅠㅠ
콘솔에서 수정하면 커스텀서비스가 오류... 반대도 마찬가지

로그인

 public Customer loginCustomer() {
     //전화번호를 입력받자 -> consoleUtil 스캐너세팅
    String phoneNumber = consoleUtil.getValueOf("전화번호 입력: ");
    
    //입력한 전화번호에 해당하는 고객정보 가져오기
    Customer customer = customerService.findOne(phoneNumber);
    
    //고객정보가 없으면(null) 고객없음 -> null 반환
    if (customer == null) {
        System.out.println("해당 고객이 존재하지 않습니다.");
        return null;
    }
    
    //비밀번호 입력 받기 -> consoleUtil 스캐너세팅
    String password = consoleUtil.getValueOf("비밀번호 입력: ");
    
    //비밀 번호 일치하면 고객 정보 불러오기
    if (customer.getPassword().equals(password)) { // customer의 getPassword가 true라면!
        //.eqauls(password) 사용자가 입력한 비밀번호와 비교
        return customer; // return customer;을 해라!
    } else { // false라면?
        System.out.println("비밀번호가 틀렸습니다."); // 라고 출력하고
        return null; // 초기로 돌아간다
    }

}

로그인도 맞게 했는지 모르겠다...

너무 모르는거 투성이... ... ...
밤까지 해도 모르는거는 모르는거에서 그치고
시간 늦어서 다음날 일어나기는 힘들고
다른사람들은 척척하는ㄷㅔ
나만 못하고 마음 급하고 머리는 아프고...

profile
공부하자개발하자으쌰으쌰

0개의 댓글