본문 바로가기
Class/220801

Class 예제(1_MemberDAO)

by pms93 2022. 8. 1.
package quiz4;

import java.util.ArrayList;

public class MemberDAOImpl implements IMemberDAO{
	private ArrayList<MemberDTO> members = new ArrayList<>();
	
	@Override
	public void insert(MemberDTO member) {
		members.add(member);
	}
	
	@Override
	public int getIdx(String email) {
		int index = -1;
		 
		for(MemberDTO m : members) {
			if(m.getEmail().equals(email)) {
				index = members.indexOf(m);
				break;
			}
		}
		return index;
	}

	@Override
	public MemberDTO selectEmail(int index) {
		return members.get(index);
	}
	
	@Override
	public void delete(int index) {
		members.remove(index);
	}
	
	@Override
	public ArrayList<MemberDTO> selectAll() {
		return members;
	}
	
	@Override
	public void update(int index, String name, String mobile) {
		MemberDTO member = members.get(index);
		
		member.setName(name);
		member.setMobile(mobile);
		
		members.set(index, member);
	}








}

'Class > 220801' 카테고리의 다른 글

Class 예제(2_Main)  (0) 2022.08.01
Class 예제(1_MemberDTO)  (0) 2022.08.01
Class 예제(1_MemberDAOInterface)  (0) 2022.08.01
Class 예제(1_Service)  (0) 2022.08.01
Class 예제(1_ServiceInterface)  (0) 2022.08.01