- 수정전 Repository
package day16;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Map_ClientRepository {
Map<Integer, Map_BreakdownDTO> b = new HashMap<>();
Map<String, Map_ClientDTO> c = new HashMap<>();
private static Map_ClientRepository repository = new Map_ClientRepository();
private Map_ClientRepository() {
}
public static Map_ClientRepository getInstance() {
return repository;
}
public boolean save( Map_ClientDTO DTO) {
if(c.put(DTO.getAccount(), DTO)==null) {
return true;
}else {
return false;
}
}
public String idCheak(String id) {
Scanner sc = new Scanner(System.in);
for(String p : c.keySet()) {
if(c.get(p).getId().equals(id)) {
System.out.println("중복 아이디");
System.out.print("다시입력 >");
id = sc.next();
continue;
}
}
return id;
}
public boolean loginCheak(String id, String pw) {
for (String d : c.keySet()) {
if (c.get(d).getId().equals(id) && c.get(d).getPassword().equals(pw)) {
return true;
}
}
return false;
}
public Map<String, Map_ClientDTO> findAll() {
return c;
}
public boolean delete(String loginId, String loginPw) {
for (String d : c.keySet()) {
if (c.get(d).getPassword().equals(loginPw) && c.get(d).getId().equals(loginPw)) {
c.remove(d);
return true;
}
}
return false;
}
public boolean update(String loginId, String loginPw, String updatePassword) {
for (String d : c.keySet()) {
if (c.get(d).getPassword().equals(loginPw) && c.get(d).getId().equals(loginId)) {
c.get(d).setPassword(updatePassword);
return true;
}
}
return false;
}
public boolean deposit(String Account, long money) {
for (String d : c.keySet()) {
if (c.get(d).getAccount().equals(Account)) {
c.get(d).setBalance(c.get(d).getBalance() + money);
Map_BreakdownDTO breakdownDTO = new Map_BreakdownDTO();
breakdownDTO.setAccount(Account);
breakdownDTO.setDivision("입금");
breakdownDTO.setDealMoney(money);
breakdownDTO.setTotalMoney(c.get(d).getBalance());
b.put(breakdownDTO.getDpo(), breakdownDTO);
return true;
}
}
return false;
}
public boolean withdraw(String Account, long money) {
for (String d : c.keySet()) {
if (c.get(d).getAccount().equals(Account)) {
if (c.get(d).getBalance() >= money) {
c.get(d).setBalance(c.get(d).getBalance() - money);
Map_BreakdownDTO breakdownDTO = new Map_BreakdownDTO();
breakdownDTO.setAccount(Account);
breakdownDTO.setDivision("출금");
breakdownDTO.setDealMoney(money);
breakdownDTO.setTotalMoney(c.get(d).getBalance());
b.put(breakdownDTO.getWit(), breakdownDTO);
return true;
} else {
return false;
}
}
}
return false;
}
public String getAccount(String loginId, String loginPw) {
for (String s : c.keySet()) {
if (c.get(s).getId().equals(loginId) && c.get(s).getPassword().equals(loginPw)) {
return c.get(s).getAccount();
}
}
return null;
}
public Map_ClientDTO findById(String loginId, String loginPw) {
for (String d : c.keySet()) {
if (c.get(d).getId().equals(loginId) && c.get(d).getPassword().equals(loginPw)) {
return c.get(d);
}
}
return null;
}
public List<Map_BreakdownDTO> breakList(String Account) {
List<Map_BreakdownDTO> list = new ArrayList<>();
for (Integer q : b.keySet()) {
if (b.get(q).getAccount().equals(Account)) {
list.add(b.get(q));
}
}
return list;
}
public boolean transferCheck(String Account) {
for (String d : c.keySet()) {
if (c.get(d).getAccount().equals(Account)) {
return true;
}
}
return false;
}
}
- 수정 후 Repository
package day16;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Map_ClientRepository {
Map<Integer, Map_BreakdownDTO> b = new HashMap<>();
Map<String, Map_ClientDTO> c = new HashMap<>();
private String login = null;
private Integer key = 1;
private static Map_ClientRepository repository = new Map_ClientRepository();
private Map_ClientRepository() {
}
public static Map_ClientRepository getInstance() {
return repository;
}
public boolean save(Map_ClientDTO DTO) {
if (c.put(DTO.getAccount(), DTO) == null) {
return true;
} else {
return false;
}
}
public boolean idCheak(String id) {
for (String p : c.keySet()) {
if (c.get(p).getId().equals(id)) {
return true;
}
}
return false;
}
public boolean loginCheak(String id, String pw) {
for (String d : c.keySet()) {
if (c.get(d).getId().equals(id) && c.get(d).getPassword().equals(pw)) {
login = d;
return true;
}
}
return false;
}
public void delete() {
c.remove(login);
login = null;
}
public void update(String updatePassword) {
c.get(login).setPassword(updatePassword);
login = null;
}
public Map_ClientDTO findById() {
if (login != null) {
return c.get(login);
}
return null;
}
public Map<String, Map_ClientDTO> findAll() {
return c;
}
public List<Map_BreakdownDTO> breakList(String Account) {
List<Map_BreakdownDTO> list = new ArrayList<>();
for (Integer q : b.keySet()) {
if (b.get(q).getAccount().equals(Account)) {
list.add(b.get(q));
}
}
return list;
}
public boolean deposit(Map_ClientDTO Account, long money) {
key = null;
if (key == null) {
Map_BreakdownDTO breakdownDTO = new Map_BreakdownDTO();
breakdownDTO.getdw(Account, money, key);
b.put(breakdownDTO.getDpo(), breakdownDTO);
return true;
}
return false;
}
public boolean withdraw(Map_ClientDTO Account, long money) {
key = 1;
if (Account.getBalance() >= money && key == 1) {
Map_BreakdownDTO breakdownDTO = new Map_BreakdownDTO();
breakdownDTO.getdw(Account, money, key);
b.put(breakdownDTO.getWit(), breakdownDTO);
return true;
} else {
return false;
}
}
public Map_ClientDTO getAccount(String transferAccount) {
for (String d : c.keySet()) {
if (c.get(d).getAccount().equals(transferAccount)) {
return c.get(d);
}
}
return null;
}
}
'나의 수업일지' 카테고리의 다른 글
인천 일보 아카데미 20일~23일 - 개인 프로젝트(콘솔 게임 만들기) (0) | 2023.03.27 |
---|---|
인천 일보 아카데미 19일차_상속-좀 더 알아보기 / 인터페이스란 ? (0) | 2023.03.20 |
인천 일보 아카데미 18일차 Map으로 수정하기 (1) | 2023.03.18 |
인천 일보 아카데미 17일차 코드리딩/리팩토링/Map으로 만들어보기 (0) | 2023.03.16 |
인천 일보 아카데미 16일차 primitive type / Wrapper class type (0) | 2023.03.16 |