[Java] Collection Exercise

Joy๐ŸŒฑยท2023๋…„ 1์›” 8์ผ
0

๐Ÿงฉ Coding Challenges

๋ชฉ๋ก ๋ณด๊ธฐ
10/20
post-thumbnail
post-custom-banner

๐Ÿงฉ ์ปฌ๋ ‰์…˜์„ ์ด์šฉํ•˜์—ฌ Joy Restaurant์˜ ๋ฉ”๋‰ด๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

๐Ÿ’โ€ WELCOME !
Joy Restaurant์˜ chef๋“ค์„ ์œ„ํ•œ ๋ฉ”๋‰ด๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”!
๋ฉ”๋‰ด๊ฐ€ ์ž์ฃผ ๋ฐ”๋€Œ๊ณ  ์ถ”๊ฐ€๋˜๋Š” Joy Restaurant์˜ ํŠน์„ฑ์ƒ, Dish์˜ ์ถ”๊ฐ€, ์ „์ฒด ์กฐํšŒ, ์ •๋ ฌ ์กฐํšŒ, ๊ฒ€์ƒ‰, ์ˆ˜์ •, ์‚ญ์ œ์˜ ๊ธฐ๋Šฅ์ด ์žˆ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.
๋˜ํ•œ Course๋กœ๋„ ์ •๋ ฌ ๋ฐ ๊ฒ€์ƒ‰์ด ๋˜์—ˆ์œผ๋ฉด ์ข‹๊ฒ ๋„ค์š”.


โ—ผ DishDTO Class

public class DishDTO {

	// ํ•„๋“œ
	private String course;
	private String dishName;
	
	// ์ƒ์„ฑ์ž
	public DishDTO() {}
	
	public DishDTO(String course, String dishName) {
		this.course = course;
		this.dishName = dishName;
	}

	// getter & setter
	public String getCourse() {
		return course;
	}

	public void setCourse(String course) {
		this.course = course;
	}
	
	public String getDishName() {
		return dishName;
	}

	public void setDishName(String dishName) {
		this.dishName = dishName;
	}

	// ๋ฉ”์†Œ๋“œ
	>>> toString() : ๋“ฑ๋ก๋œ ๊ฐ ๋ฆฌ์ŠคํŠธ์˜ 16์ง„์ˆ˜ ํ•ด์‰ฌ์ฝ”๋“œ๊ฐ€ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜๋˜๊ฒŒ๋” ํ•˜๋Š” ๋ฉ”์†Œ๋“œ (์—†์œผ๋ฉด ์ฃผ์†Œ๊ฐ’์ด ๋ฐ˜ํ™˜๋จ)
	@Override
	public String toString() {
		return "DishDTO [Course : " + course + " | DishName : " + dishName + "]";
	}
}

โ—ผ DishController Class

public class DishController { // ์ •๋ณด์˜ ์ถ”๊ฐ€, ์ €์žฅ, ์ˆ˜์ •, ์‚ญ์ œ๋ฅผ ๋‹ด๋‹น (ArrayList)

	// Dish ๋ชฉ๋ก์„ ์ €์žฅํ•ด๋‘๊ธฐ ์œ„ํ•œ ๋ฆฌ์ŠคํŠธ (DishDTO๋งŒ ์ €์žฅ)
	private List<DishDTO> dishList = new ArrayList<>();
	
	// '[1] Dish ์ถ”๊ฐ€'๋ฅผ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void addList(DishDTO dish) {
		dishList.add(dish);
	}
	
	// '[2] Dish ์ „์ฒด ์กฐํšŒ'๋ฅผ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public List<DishDTO> selecetList() { // Q1. List<DishDTO>๊ฐ€ ์™œ ์—ฌ๊ธฐ์— ๋ฐ˜ํ™˜ํ˜•์œผ๋กœ ์žˆ์„๊นŒ์š”? RestaurantMenu ํด๋ž˜์Šค์—์„œ SelectList()๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ Dish ๋ชฉ๋ก์„ ๋ฆฌํ„ดํ•ด์ค„ ๋•Œ List<DishDTO>์—์„œ์ฐธ์กฐํ•ด์™€์•ผํ•˜๊ธฐ๋•Œ๋ฌธ (๋ฐ˜ํ™˜ํ˜•)
		return dishList; 
		// ์œ„์—์„œ ์ €์žฅํ•ด๋‘” Dish ๋ชฉ๋ก์„ ๋ฆฌํ„ดํ•ด์คŒ
	}
	
	// '[4] Dish๋ช…์œผ๋กœ ๊ฒ€์ƒ‰'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public List<DishDTO> searchDish(String dishName) {
		// Dish๋ช…์„ ๊ฒ€์ƒ‰ํ•ด์„œ ํ•ด๋‹น ํ‚ค์›Œ๋“œ๊ฐ€ ํฌํ•จ๋˜๋Š” Dish๋“ค์„ ๋ฆฌํ„ด ๋ฐ›๊ธฐ ์œ„ํ•œ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
		List<DishDTO> searchList = new ArrayList<>();
		
		for(DishDTO dishV : dishList) { // ์ €์žฅ๋œ Dish ๋ชฉ๋ก์— ์ ‘๊ทผ
			
			if(dishV.getDishName().contains(dishName)); {
			// ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋“ค์–ด์˜จ dishName์ด DishDTO์˜ DishName์— ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€์˜ ์—ฌ๋ถ€
				searchList.add(dishV);
				// ํ•ด๋‹น ํ‚ค์›Œ๋“œ๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ๋Š” ์š”๋ฆฌ๋“ค๋งŒ, searchList์— ์ถ”๊ฐ€ 
			}
		}	
		return searchList;
		// ์ถ”๊ฐ€ ์™„๋ฃŒ๋œ searchList ๋ฆฌํ„ด
	}
	
	// '[5] Course๋ช…์œผ๋กœ ๊ฒ€์ƒ‰'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public List<DishDTO> searchCourse(String course) {
		// Course๋ช…์„ ๊ฒ€์ƒ‰ํ•ด์„œ ํ•ด๋‹น ํ‚ค์›Œ๋“œ๊ฐ€ ํฌํ•จ๋˜๋Š” Course๋“ค์„ ๋ฆฌํ„ด ๋ฐ›๊ธฐ ์œ„ํ•œ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
		List<DishDTO> searchList = new ArrayList<>();
		
		for(DishDTO courseV : dishList) { // ์ €์žฅ๋œ Dish ๋ชฉ๋ก์— ์ ‘๊ทผ
			
			if(courseV.getCourse().contains(course)) {
				// ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋“ค์–ด์˜จ course๊ฐ€ DishDTO์˜ Course์— ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€์˜ ์—ฌ๋ถ€
				searchList.add(courseV);
				// ํ•ด๋‹น ํ‚ค์›Œ๋“œ๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ๋Š” ์ฝ”์Šค๋“ค๋งŒ, searchList์— ์ถ”๊ฐ€ 
			}
		}
		return searchList;
		// ์ถ”๊ฐ€ ์™„๋ฃŒ๋œ searchList ๋ฆฌํ„ด
	}
	
	// '[6] Dish ์ •๋ณด ์ˆ˜์ •'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public int editDish(String oldDishname, DishDTO editDish) { // : (์ˆ˜์ •ํ•  Dish๋ช…, ์ƒˆ๋กœ์šด Course๋ช… ๋ฐ Dish๋ช…)
		
		DishDTO old = null;
		
		for(int i = 0; i < dishList.size(); i++) { // : Dish ๋ชฉ๋ก์ด ์ €์žฅ๋˜์–ด ์žˆ๋Š” dishList์— ํ•˜๋‚˜์”ฉ ์ ‘๊ทผ
			
			if(dishList.get(i).getDishName().equals(oldDishname)) { // : ์ ‘๊ทผํ•œ ๋ชฉ๋ก ์ค‘ ์ˆ˜์ •ํ•  Dish๋ช…๊ณผ ์™„๋ฒฝํžˆ ์ผ์น˜ํ•˜๋Š” ๊ฒƒ์ด ์žˆ๋‹ค๋ฉด,
				
				old = dishList.set(i, editDish); // : ํ•ด๋‹นํ•˜๋Š” ์œ„์น˜(i)์— ์žˆ๋Š” Dish๋ช…์„ old์— ๋ฐ˜ํ™˜ํ•œ ๋’ค RestaurantMenu ํด๋ž˜์Šค์˜ editDish ๋ฉ”์†Œ๋“œ์—์„œ ์˜จ editDish๋กœ ์ˆ˜์ •
			}
		}
		// set() ๋ฉ”์†Œ๋“œ๋Š” ์ˆ˜์ • ์ „, old์˜ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์ˆ˜์ •๋จ. ๋”ฐ๋ผ์„œ ๋ฐ˜ํ™˜์ด ๋œ ๊ฒฝ์šฐ๋Š” ์ˆ˜์ •์ด ๋˜์—ˆ๋‹ค๋Š” ์˜๋ฏธ.
		// old์˜ ๊ฐ’์ด ๋ฐ˜ํ™˜๋œ ๊ฒฝ์šฐ 1 ๋ฆฌํ„ด, ๋ฐ˜ํ™˜๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ 0 ๋ฆฌํ„ด
		return old != null ? 1 : 0;
		// : old ์ด์ œ null ์•„๋‹ˆ์ง€? ์‘ = 1, ์•„๋‹ˆ = 0
	}	
	
	// '[7] Dish ์‚ญ์ œ'๋ฅผ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public int removeDish(String dishname) { // : (์‚ญ์ œํ•  Dish๋ช…)
		
		DishDTO old = null;
		
		for(int i = 0; i < dishList.size(); i++) { // : Dish ๋ชฉ๋ก์ด ์ €์žฅ๋˜์–ด ์žˆ๋Š” dishList์— ํ•˜๋‚˜์”ฉ ์ ‘๊ทผ
			
			if(dishList.get(i).getDishName().equals(dishname)) { // : ์ ‘๊ทผํ•œ ๋ชฉ๋ก ์ค‘ ์‚ญ์ œํ•  Dish๋ช…๊ณผ ์™„๋ฒฝํžˆ ์ผ์น˜ํ•˜๋Š” ๊ฒƒ์ด ์žˆ๋‹ค๋ฉด,
				
				old = dishList.remove(i); // : ํ•ด๋‹นํ•˜๋Š” ์œ„์น˜(i)์— ์žˆ๋Š” Dish๋ช…์„ old์— ๋ฐ˜ํ™˜ํ•œ ๋’ค ์‚ญ์ œ
			}
		}
		// remove() ๋ฉ”์†Œ๋“œ๋Š” ์‚ญ์ œ ์ „, old์˜ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์ˆ˜์ •๋จ. ๋”ฐ๋ผ์„œ ๋ฐ˜ํ™˜์ด ๋œ ๊ฒฝ์šฐ๋Š” ์‚ญ์ œ๊ฐ€ ๋˜์—ˆ๋‹ค๋Š” ์˜๋ฏธ.
		// old์˜ ๊ฐ’์ด ๋ฐ˜ํ™˜๋œ ๊ฒฝ์šฐ 1 ๋ฆฌํ„ด, ๋ฐ˜ํ™˜๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ 0 ๋ฆฌํ„ด
		return old != null ? 1 : 0;
		// : old ์ด์ œ null ์•„๋‹ˆ์ง€? ์‘ = 1, ์•„๋‹ˆ = 0
	}
}

โ—ผ 3 Classes implements Comparator<DishDTO>

public class AscCourse implements Comparator<DishDTO> {
	
	// ์ •๋ ฌ ์ค‘, '[2] Course๋ณ„ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ (๊ธฐ์ค€)
	@Override
	public int compare(DishDTO o1, DishDTO o2) {
		return o1.getCourse().compareTo(o2.getCourse());
	}
}
public class DescDishName implements Comparator<DishDTO> {

	// ์ •๋ ฌ ์ค‘, '[3] Dish๋ช… ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ (๊ธฐ์ค€)
	@Override
	public int compare(DishDTO o1, DishDTO o2) {
		return o2.getDishName().compareTo(o1.getDishName());
	}
}
public class DescCourse implements Comparator<DishDTO>{
	
	// ์ •๋ ฌ ์ค‘, '[4] Course๋ณ„ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ (๊ธฐ์ค€)
	@Override
	public int compare(DishDTO o1, DishDTO o2) {
		return o2.getCourse().compareTo(o1.getCourse());
	}
}

โ—ผ Application Class

public class RestaurantMenu { // ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ๋“ค์„ ์ถœ๋ ฅํ•ด์ฃผ๋Š” ๊ฒƒ ๋‹ด๋‹น

	// DishController ๊ฐ์ฒด ์ƒ์„ฑ
	private DishController dishController = new DishController();
	
	Scanner sc = new Scanner(System.in);
	
	public void mainView() {
		
		XXX :
		while(true) {			
			System.out.println("");
			System.out.println("======= Menu =======");
			System.out.println("[1] Dish ์ถ”๊ฐ€");
			System.out.println("[2] Dish ์ „์ฒด ์กฐํšŒ");
			System.out.println("[3] ์ •๋ ฌํ•˜์—ฌ ์กฐํšŒ");
			System.out.println("[4] Dish๋ช…์œผ๋กœ ๊ฒ€์ƒ‰");
			System.out.println("[5] Course๋ช…์œผ๋กœ ๊ฒ€์ƒ‰");
			System.out.println("[6] Dish ์ •๋ณด ์ˆ˜์ •");
			System.out.println("[7] Dish ์‚ญ์ œ");
			System.out.println("[0] ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ");
			
			System.out.print("Menu ์„ ํƒ : ");
			int menu = sc.nextInt();
			
			switch(menu) {
			case 1: addList();
				break;
			case 2: selectList();
				break;
			case 3: sortList();
				break;
			case 4 : searchDish();
				break;
			case 5 : searchCourse();
				break;
			case 6 : editDish();
				break;
			case 7 : removeDish();
				break;
			case 0 : System.out.println("ํ”„๋กœ๊ทธ๋žจ์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค :) ");
				break XXX; // while๋ฌธ ์ข…๋ฃŒ
			default : System.out.println("์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ ๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” :( ");
				break;
			}
		}
	}
	
	// '[1] Dish ์ถ”๊ฐ€'๋ฅผ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void addList() {
		System.out.println("================= Dish ์ถ”๊ฐ€ =================");
		System.out.println(" Appetizer | Soup | Entree | Main | Dessert");
		System.out.println("============================================");		
		sc.nextLine();
		
		System.out.print("Course ์ž…๋ ฅ : ");
		String course = sc.nextLine();
		System.out.print("Dish ์ž…๋ ฅ : ");
		String dish = sc.nextLine();
		
		dishController.addList(new DishDTO(course, dish));
	}
	
	// '[2] Dish ์ „์ฒด ์กฐํšŒ'๋ฅผ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void selectList() {		
		System.out.println("=============== Dish ์ „์ฒด ์กฐํšŒ ===============");
		// ์œ„์—์„œ ์ƒ์„ฑํ•œ dishcontroller ์ฐธ์กฐ ๋ณ€์ˆ˜๋กœ DishController์˜ selectList() ํ˜ธ์ถœ
		List<DishDTO> dishList = dishController.selectList(); // selectList()๋กœ ๋ถ€ํ„ฐ dishList ๋ฆฌํ„ด๋ฐ›์Œ 
		
		if (!dishList.isEmpty()) { // : dishList๊ฐ€ ๋น„์–ด์žˆ์ง€ ์•Š์„ ๊ฒฝ์šฐ,
			for (DishDTO dish : dishList) {
				System.out.println(dish); // dishList ๋ชฉ๋ก ์ถœ๋ ฅ
			}
		} else {
			System.out.println("๋“ฑ๋ก๋œ Dish๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค :("); // dishList๊ฐ€ ๋น„์–ด์žˆ์„ ๊ฒฝ์šฐ์˜ ์ถœ๋ ฅ๋ฌธ
		}
	}
	
	// '[3] ์ •๋ ฌํ•˜์—ฌ ์กฐํšŒ'๋ฅผ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void sortList() {
		System.out.println("================ ์ •๋ ฌ ๋ฐฉ์‹ ์„ ํƒ ================");
		System.out.println("[1] Dish๋ช… ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ");
		System.out.println("[2] Course๋ณ„ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ");
		System.out.println("[3] Dish๋ช… ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ");
		System.out.println("[4] Course๋ณ„ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ");
		
		System.out.print("Menu ์„ ํƒ : ");
		int menu = sc.nextInt();
		
		ascDesc(menu);
	}
	
	// ์ •๋ ฌ ์ค‘, '[1] Dish๋ช… ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ'๋ฐ 3๊ฐ€์ง€ ์ •๋ ฌ๊ธฐ์ค€ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void ascDesc(int menu) {
		System.out.println("============== ์„ ํƒ๋œ ์ •๋ ฌ๋กœ ์กฐํšŒ ==============");
		// ์œ„์—์„œ ์ƒ์„ฑํ•œ dishcontroller ์ฐธ์กฐ ๋ณ€์ˆ˜๋กœ DishController์˜ selectList() ํ˜ธ์ถœ
		List<DishDTO> dishList = dishController.selcetList(); // selcetList()๋กœ ๋ถ€ํ„ฐ dishList ๋ฆฌํ„ด๋ฐ›์Œ
		
		// ์ •๋ ฌ ์‹œ ์›๋ณธ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฏ€๋กœ ์‚ฌ๋ณธ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ„๋„๋กœ ์ƒ์„ฑ
		List<DishDTO> sortList = new ArrayList<>();
		sortList.addAll(dishList); // sortList๋Š” dishList์˜ ์‚ฌ๋ณธ
		// addAll : Collection ํƒ€์ž… ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€
		
		if(menu == 1) {
			
			// ์ต๋ช… ํด๋ž˜์Šค ์‚ฌ์šฉ
			sortList.sort(new Comparator<DishDTO>() {
				
				@Override
				public int compare(DishDTO o1, DishDTO o2) {
					return o1.getDishName().compareTo(o2.getDishName());
				}
			});
			
		// Comparator๋ฅผ ์ƒ์†ํ•œ ํด๋ž˜์Šค(์ •๋ ฌ๊ธฐ์ค€)๋ฅผ ์‚ฌ์šฉ
		} else if (menu == 2) {
			sortList.sort(new AscCourse()); //'[2] Course๋ณ„ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ'์˜ ๊ธฐ์ค€ ๋ฉ”์†Œ๋“œ
		
		} else if (menu == 3) {
			sortList.sort(new DescDishName()); //'[3] Dish๋ช… ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ'์˜ ๊ธฐ์ค€ ๋ฉ”์†Œ๋“œ
		
		} else {
			sortList.sort(new DescCourse()); //'[4] Course๋ณ„ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ'์˜ ๊ธฐ์ค€ ๋ฉ”์†Œ๋“œ
		}
		
		for(int i = 0; i < sortList.size(); i++) {
			System.out.println(sortList.get(i)); // : sortList ์ธ๋ฑ์Šค์˜ ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์˜ด
		}
	}

	// '[4] Dish๋ช…์œผ๋กœ ๊ฒ€์ƒ‰'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void searchDish() {
		System.out.println("============== Dish๋ช…์œผ๋กœ ๊ฒ€์ƒ‰ ==============");
		sc.nextLine();
		System.out.print("Dish๋ช… ์ž…๋ ฅ : ");
		List<DishDTO> searchList = dishController.searchDish(sc.nextLine()); // ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’์„ ๋ฐ”๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ณด๋ƒ„
	
		if(!searchList.isEmpty()) { // : searchList๊ฐ€ ๋น„์–ด์žˆ์ง€ ์•Š์„ ๊ฒฝ์šฐ,
			for(int i = 0; i < searchList.size(); i++) {
				System.out.println(searchList.get(i)); // : searchList ์ธ๋ฑ์Šค์˜ ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์˜ด
			}
		} else {
			System.out.println("๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค :(");
		}
	}
	
	// '[5] Course๋ช…์œผ๋กœ ๊ฒ€์ƒ‰'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void searchCourse() {
		System.out.println("============== Course๋ณ„๋กœ ๊ฒ€์ƒ‰ ==============");
		System.out.println(" Appetizer | Soup | Entree | Main | Dessert");
		System.out.println("============================================");	
		sc.nextLine();
		System.out.print("Course ์ž…๋ ฅ : ");
		List<DishDTO> searchList = dishController.searchCourse(sc.nextLine()); // ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’์„ ๋ฐ”๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ณด๋ƒ„
	
		if(!searchList.isEmpty()) {
			for(int i = 0; i < searchList.size(); i++) {
				System.out.println(searchList.get(i)); // : searchList ์ธ๋ฑ์Šค์˜ ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์˜ด
			}
		} else {
			System.out.println("๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค :(");
		}
	}
	
	// '[6] Dish ์ •๋ณด ์ˆ˜์ •'์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void editDish() {
		System.out.println("============== Dish ์ •๋ณด ์ˆ˜์ • ==============");
		sc.nextLine();
		System.out.print("์ˆ˜์ •ํ•  Dish๋ช… : ");
		String oldDishName = sc.nextLine();
		System.out.println("============================================");
		System.out.println(" Appetizer | Soup | Entree | Main | Dessert");
		System.out.println("============================================");
		System.out.print("์ƒˆ๋กœ์šด Dish์˜ Course : ");
		String newCourseName = sc.nextLine();
		System.out.print("์ƒˆ๋กœ์šด Dish๋ช… : ");
		String newDishName = sc.nextLine();
		
		DishDTO editDish = new DishDTO(newCourseName, newDishName); // editDish : ์ƒˆ๋กœ์šด Dish๋ช… ๋ฐ Dish๋ช… 
		int result = dishController.editDish(oldDishName, editDish); // DishController ํด๋ž˜์Šค์˜ editDish ๋ฉ”์†Œ๋“œ์— (์ˆ˜์ •ํ•  Dish๋ช…, ์ƒˆ๋กœ์šด Course๋ช… ๋ฐ Dish๋ช…) ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ
		
		// DishController ํด๋ž˜์Šค์˜ editDish ๋ฉ”์†Œ๋“œ ์‹คํ–‰๋œ ํ›„, ๋ฆฌํ„ด๋ฐ›์€ result์˜ ๊ฐ’์€ 0๋˜๋Š” 1 
		if(result > 0) {
			System.out.println("์ˆ˜์ •์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค :)");
		} else {
			System.out.println("์ˆ˜์ •ํ•  Dish๋ฅผ ์ฐพ์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค :(");
		}
	}
	
	// '[7] Dish ์‚ญ์ œ'๋ฅผ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ
	public void removeDish() {
		System.out.println("================ Dish ์‚ญ์ œ ================");
		sc.nextLine();
		System.out.print("์‚ญ์ œํ•  Dish๋ช… : ");
		int result = dishController.removeDish(sc.nextLine()); // DishController ํด๋ž˜์Šค์˜ editDish ๋ฉ”์†Œ๋“œ์— (์‚ญ์ œํ•  Dish๋ช…) ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ
		
		// DishController ํด๋ž˜์Šค์˜ removeDish ๋ฉ”์†Œ๋“œ ์‹คํ–‰๋œ ํ›„, ๋ฆฌํ„ด๋ฐ›์€ result์˜ ๊ฐ’์€ 0๋˜๋Š” 1 
		if (result > 0) {
			System.out.println("์‚ญ์ œ๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค :)");
		} else {
			System.out.println("์‚ญ์ œํ•  Dish๋ฅผ ์ฐพ์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค :(");
		}
	}
}

โ—ผ Application Class

public class Application {

	public static void main(String[] args) {
		
		RestaurantMenu rm = new RestaurantMenu();
		
		rm.mainView();
	}
}

profile
Tiny little habits make me
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€