Team Project

[Java] ์ถ•๊ตฌ ์„ ์ˆ˜ ์ด์  ์‹œ์žฅ

ITs Min 2023. 12. 14.

๐Ÿ”ฅ ๊ธฐ๋Šฅ


๐Ÿ’ง ์ฝ”๋“œ

package team_project;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

class FootballPlayer { // ์ถ•๊ตฌ์„ ์ˆ˜ ํด๋ž˜์Šค
	private int pk; // PK, ๊ฐ์ฒด ๊ณ ์œ  id๋กœ ์‚ฌ์šฉ
	private String name; // ์„ ์ˆ˜ ์ด๋ฆ„
	private String position; // ์„ ์ˆ˜ ํฌ์ง€์…˜
	private int totalPower; // ์„ ์ˆ˜ ๋Šฅ๋ ฅ์น˜
	private int price; // ๊ฐ€๊ฒฉ
	private int ea; // ์ˆ˜๋Ÿ‰

	FootballPlayer(int pk, String name, String position, int totalPower, int price, int ea) {
		this.pk = pk;
		this.name = name;
		this.position = position; // FW, MF, DF, GK
		this.totalPower = totalPower;
		this.price = price;
		this.ea = ea;
	}

	public int getPk() {
		return pk;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public int getTotalPower() {
		return totalPower;
	}

	public void setTotalPower(int totalPower) {
		this.totalPower = totalPower;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getEa() {
		return ea;
	}

	public void setEa(int ea) {
		this.ea = ea;
	}

	@Override // ์œ ์ €ํ•œํ…Œ PK ์•ˆ๋ณด์ด๋„๋ก ์„ค์ •
	public String toString() {
		String ret = "[" + position + " "+ name + " ๋Šฅ๋ ฅ์น˜ : " + totalPower + ", " + price+"$";
		if (this.ea == 0) {
			return ret + ", ์žฌ๊ณ ์—†์Œ]";
		} else {
			return ret + ", ์ˆ˜๋Ÿ‰=" + ea + "]";
		}
	}

	public void sell(int cnt) {
		this.ea -= cnt;
	}

	public static Comparator<FootballPlayer> byPrice = new Comparator<FootballPlayer>() {
		@Override
		public int compare(FootballPlayer p1, FootballPlayer p2) {
			return p2.price - p1.price;
		}
	};

	public static Comparator<FootballPlayer> byTotalPower = new Comparator<FootballPlayer>() {
		@Override
		public int compare(FootballPlayer p1, FootballPlayer p2) {
			return p2.totalPower - p1.totalPower;
		}
	};

	public static Comparator<FootballPlayer> byPk = new Comparator<FootballPlayer>() {
		@Override
		public int compare(FootballPlayer p1, FootballPlayer p2) {
			return p2.pk - p1.pk;
		}
	};

	public static Comparator<FootballPlayer> byName = new Comparator<FootballPlayer>() {
		@Override
		public int compare(FootballPlayer p1, FootballPlayer p2) {
			return p2.name.compareTo(p1.name);
		}
	};
}

public class FootballMarket {

	public static int PK = 1001; // ๊ฐ์ฒด๊ฐ€ ๋งŒ๋“ค์–ด์งˆ๋–„๋งˆ๋‹ค ++
	public final static int MANAGERMODE = 231121;
	public static Scanner sc = new Scanner(System.in);
	public static ArrayList<FootballPlayer> datas = new ArrayList<FootballPlayer>();

	/*
	 * Utils
	 */

	// ๋ฌธ์ž์—ด ์ž…๋ ฅ๋ฐ›๊ธฐ
	public static String inputString(String msg) {
		System.out.print(msg);
		return sc.next();
	}




	// ํฌ์ง€์…˜ ์ž…๋ ฅ๋ฐ›๊ธฐ ๋ฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ
	public static String getPosition(String msg) {
		System.out.print(msg);
		System.out.print("(FW / MF / DF / GK) >> ");
		while (true) {
			String position = sc.next();
			if (position.equals("FW") || position.equals("MF") || position.equals("DF") || position.equals("GK")) {
				return position;
			}
			System.out.println("ํฌ์ง€์…˜์€ FW, MF, DF, GK ์ค‘์—๋งŒ ์ž…๋ ฅํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.");
			System.out.print("๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” >> ");
		}
	}

	// Y or N ์ž…๋ ฅ๋ฐ›๊ธฐ ๋ฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ
	public static String getAnswer(String msg) {
		System.out.print(msg);
		while (true) {
			String answer = sc.next();
			if (answer.equals("Y") || answer.equals("N")) {
				return answer;
			}
			System.out.println("Y ๋˜๋Š” N ๋งŒ ์ž…๋ ฅ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.");
			System.out.print("๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” >> ");
		}
	}



	/*
	 * Football Player Buy
	 */

	public static void buy(ArrayList<FootballPlayer> players) {
		int eaCnt = 0;
		for (int i = 0; i < players.size(); i++) {
			eaCnt += players.get(i).getEa();
		}
		if (eaCnt <= 0) {
			System.out.println("๋“ฑ๋ก๋œ ๋ชจ๋“  ์„ ์ˆ˜์˜ ์žฌ๊ณ ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.");
			return;
		}
		while (true) {

			int choiceNum = inputNum("๊ตฌ๋งคํ•  ์„ ์ˆ˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ ", 1, players.size());
			if (players.get(choiceNum - 1).getEa() <= 0) {
				System.out.println("ํ•ด๋‹น์„ ์ˆ˜ ์žฌ๊ณ ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.");
				continue;
			}

			int cnt = inputNum("๊ตฌ์ž…ํ•  ์ˆ˜๋Ÿ‰ ์ž…๋ ฅ ", 1, players.get(choiceNum - 1).getEa());
			System.out.println(cnt + "๊ฐœ๋ฅผ ๊ตฌ์ž…ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ ?");

			String answer = getAnswer("Y or N >> ");
			if (answer.equals("Y")) {
				System.out.println(players.get(choiceNum - 1).getName() + " " + cnt + "๊ฐœ ๊ตฌ์ž…์™„๋ฃŒ!");
				players.get(choiceNum - 1).sell(cnt);
			} else {
				System.out.println("๊ตฌ์ž… ์ทจ์†Œ");
			}
			break;
		}
	}

	/*
	 * Manager Mode
	 */


	// ์„ ์ˆ˜ ๋ชจ๋‘ ์ถœ๋ ฅ ( ์ •๋ณด ๋ณ€๊ฒฝ์ด๋‚˜ ์‚ญ์ œ์—์„œ ๋ชฉ๋ก์„ ๋„์šฐ๊ธฐ ์œ„ํ•จ)
	public static void printAllFootballPlayer() {

		for (int i = 0; i < datas.size(); i++) {
			System.out.println("[PK-" + datas.get(i).getPk() + "] " + datas.get(i));
		}
	}

	// ๊ด€๋ฆฌ์ž ๋ชจ๋“œ ์‹คํ–‰
	public static void execManagerMode() {
		System.out.println("๊ด€๋ฆฌ์ž ๋ชจ๋“œ์ž…๋‹ˆ๋‹ค");
		printManagermode();
	}

	// ๊ด€๋ฆฌ์ž ๋ฉ”์ธ ๋ฉ”๋‰ด
	public static void printManagermode() {
		while (true) {
			System.out.println("1. ์„ ์ˆ˜ ์ถ”๊ฐ€");
			System.out.println("2. ์„ ์ˆ˜ ์ •๋ณด ๋ณ€๊ฒฝ");
			System.out.println("3. ์„ ์ˆ˜ ์‚ญ์ œ");
			System.out.println("0. ๊ด€๋ฆฌ์ž ๋ชจ๋“œ ์ข…๋ฃŒ");
			if (chooseManagermenu() == 0) {
				break;
			}
		}
	}

	// ๊ด€๋ฆฌ์ž ๋ฉ”์ธ ๋ฉ”๋‰ด ๋ฒˆํ˜ธ ์„ ํƒ
	public static int chooseManagermenu() {
		int action = inputNum("๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", 0, 3);
		if (action == 1) { // ์„ ์ˆ˜ ์ถ”๊ฐ€
			addFootballPlayer();
		} else if (action == 2) { // ์„ ์ˆ˜์ •๋ณด ๋ณ€๊ฒฝ
			updateFootballPlayer();
		} else if (action == 3) { // ์„ ์ˆ˜ ์‚ญ์ œ
			deleteFootballPlayer();
		} else if (action == 0) { // ์‚ฌ์šฉ์žํ™”๋ฉด์œผ๋กœ ์ด๋™
			System.out.println("๊ด€๋ฆฌ์ž๋ชจ๋“œ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค...");
		}
		return action;
	}


	// ๊ฐ€๊ฒฉ ๋ณ€๊ฒฝ
	public static void UpdatePrice(int i) {
		while (true) {
			int price = inputNum("์ƒˆ๋กœ์šด ๊ฐ€๊ฒฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", 1000, 10000);
			if (price != datas.get(i).getPrice()) {
				datas.get(i).setPrice(price);
				System.out.println(datas.get(i).getName() + "์„ ์ˆ˜ " + datas.get(i).getPrice() + "์› ๋ณ€๊ฒฝ์™„๋ฃŒ!");
				break;
			} else {
				System.out.println("๊ฐ™์€ ๊ฐ€๊ฒฉ์€ ์ž…๋ ฅํ•˜์‹ค ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
			}
		}
	}

	// ๋Šฅ๋ ฅ์น˜ ๋ณ€๊ฒฝ
	public static void UpdateTotalPower(int i) {
		while (true) {
			int power = inputNum("์ƒˆ๋กœ์šด ๋Šฅ๋ ฅ์น˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", 40, 100);
			if (power != datas.get(i).getTotalPower()) {
				datas.get(i).setTotalPower(power);
				System.out.println(datas.get(i).getName() + "์„ ์ˆ˜ ๋Šฅ๋ ฅ์น˜ " + datas.get(i).getTotalPower() + " ๋ณ€๊ฒฝ์™„๋ฃŒ!");
				break;
			} else {
				System.out.println("๊ฐ™์€ ๋Šฅ๋ ฅ์น˜๋Š” ์ž…๋ ฅํ•˜์‹ค ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
			}

		}
	}

	// ์ˆ˜๋Ÿ‰ ๋ณ€๊ฒฝ
	public static void UpdateEa(int i) {
		while (true) {
			int ea = inputNum("์ƒˆ๋กœ์šด ์ˆ˜๋Ÿ‰์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", 1, 10);
			if (ea != datas.get(i).getEa()) {
				datas.get(i).setEa(ea);
				System.out.println(datas.get(i).getName() + "์„ ์ˆ˜ ์žฌ๊ณ  " + datas.get(i).getEa() + "๊ฐœ ๋ณ€๊ฒฝ์™„๋ฃŒ!");
				break;
			} else {
				System.out.println("๊ฐ™์€ ์ˆ˜๋Ÿ‰์œผ๋กœ๋Š” ์ž…๋ ฅํ•˜์‹ค ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
			}
		}

	}


	
	// PK ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ
	public static int inputIndex() {
		int i = 0;
		while (true) {
			try {
				int firstPK = datas.get(0).getPk(); // datas๋ฆฌ์ŠคํŠธ๋Š” ์›๋ณธ๋ฐ์ดํ„ฐ๋กœ ์ˆœ์„œ๋ฅผ ์„ž์ง€์•Š๊ณ  PK๋Š” ํ•ญ์ƒ ์ฆ๊ฐ€ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค.
				int lastPK = datas.get(datas.size() - 1).getPk();
				int changePlayer = inputNum("์„ ์ˆ˜์˜ PK๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” ", firstPK, lastPK);// ์ˆ˜์ •, ํ˜„์ง„ =>
				for (i = 0; i < datas.size(); i++) { // datas๋ฆฌ์ŠคํŠธ์˜ 0๋ฒˆ์งธ ์ธ๋ฑ์Šค PK๊ฐ’ ๋ถ€ํ„ฐ
					if (datas.get(i).getPk() == changePlayer) { // datas๋ฆฌ์ŠคํŠธ์˜ ๋งˆ์ง€๋ง‰ ์ธ๋ฑ์Šค PK๊ฐ’์€
						System.out.println("์„ ํƒ๋œ ์„ ์ˆ˜ : [" + datas.get(i).getName() + "]");
						return i; // datas๋ฆฌ์ŠคํŠธ์˜ size()-1์„ ํ•ด์ฃผ์–ด์•ผ
									// ๋ฆฌ์ŠคํŠธ์˜ ๋งˆ์ง€๋ง‰ ์ธ๋ฑ์Šค PK๊ฐ’์ด ๋ฉ๋‹ˆ๋‹ค.
					}
				}
				System.out.println("์œ ํšจํ•˜์ง€ ์•Š์€ PK์ž…๋‹ˆ๋‹ค.");
			} catch (Exception e) {
				System.out.println("์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”");
				sc.nextLine();
			}
		}
	}
	
	// ์„ ์ˆ˜ ์ •๋ณด ๋ณ€๊ฒฝ
	public static void updateFootballPlayer() {
		if (!checkListEmpty()) {
			printAllFootballPlayer();
			int i = inputIndex();
			System.out.println("1. ๊ฐ€๊ฒฉ ๋ณ€๊ฒฝ");
			System.out.println("2. ๋Šฅ๋ ฅ์น˜ ๋ณ€๊ฒฝ");
			System.out.println("3. ์ˆ˜๋Ÿ‰ ๋ณ€๊ฒฝ");
			int select = inputNum("์–ด๋–ค์ •๋ณด๋ฅผ ๋ณ€๊ฒฝํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?", 1, 3);
			if (select == 1) {
				UpdatePrice(i);
			} else if (select == 2) {
				UpdateTotalPower(i);
			} else if (select == 3) {
				UpdateEa(i);
			}
		}
	}

	// ๋ฐฐ์—ด๋ฆฌ์ŠคํŠธ๊ฐ€ ๋น„์–ด์žˆ๋Š”์ง€ ๊ฒ€์‚ฌ
	public static boolean checkListEmpty() {
		if (datas.size() <= 0) {
			System.out.println("๋“ฑ๋ก๋œ ์„ ์ˆ˜๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค...");
			return true;
		}
		return false;
	}
	
	// ์„ ์ˆ˜ ์‚ญ์ œ
	public static void deleteFootballPlayer() {
		if (!checkListEmpty()) {
			printAllFootballPlayer();
			int i = inputIndex();
			String name = datas.get(i).getName();
			datas.remove(i);
			System.out.println(name + " ์„ ์ˆ˜์‚ญ์ œ ์„ฑ๊ณต!");
		}
	}

	// ์„ ์ˆ˜ ์ถ”๊ฐ€
	public static void addFootballPlayer() {
		System.out.println("์„ ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.");
		String name = inputString("์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” >> ");
		String position = getPosition("ํฌ์ง€์…˜์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”");
		int totalPower = inputNum("๋Šฅ๋ ฅ์น˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", 40, 100);
		int price = inputNum("๊ฐ€๊ฒฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", 1000, 10000);
		int ea = inputNum("์ˆ˜๋Ÿ‰์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", 1, 10);
		datas.add(new FootballPlayer(PK++, name, position, totalPower, price, ea));
		System.out.println(name + " ์„ ์ˆ˜ " + ea + "๊ฐœ ๋“ฑ๋ก ์„ฑ๊ณต!");
	}

	/*
	 * Functions
	 */

	// ๊ฐ€๊ฒฉ๋ณ„ ์ถœ๋ ฅ
	public static void printByPrice() {
		if (!checkListEmpty()) {
			ArrayList<FootballPlayer> tmpDatas = new ArrayList<FootballPlayer>(datas);
			tmpDatas.sort(FootballPlayer.byPrice);
			for (int i = 0; i < tmpDatas.size(); i++) {
				System.out.println((i + 1) + ". " + tmpDatas.get(i));
			}
			buy(tmpDatas);
		}
	}

	// ๋Šฅ๋ ฅ์น˜๋ณ„ ์ถœ๋ ฅ
	public static void printByTotalPower() {
		if (!checkListEmpty()) {
			ArrayList<FootballPlayer> tmpDatas = new ArrayList<FootballPlayer>(datas);
			tmpDatas.sort(FootballPlayer.byTotalPower);
			for (int i = 0; i < tmpDatas.size(); i++) {
				System.out.println((i + 1) + ". " + tmpDatas.get(i));
			}
			buy(tmpDatas);
		}
	}

	public static void printByMainPosition(ArrayList<FootballPlayer> players, String position) { // ํฌ์ง€์…˜ ์ž…๋ ฅ // ๋ฐฐ์—ด ๋„ฃ๊ธฐ
		// ๋ฐฐ์—ด ํ•˜๋‚˜ ๋งŒ๋“ ๋‹ค tmpDatas
		ArrayList<FootballPlayer> tmpDatas = new ArrayList<FootballPlayer>();
		int i = 0;
		for (FootballPlayer player : players) {
			if (player.getPosition().equals(position)) { // ํฌ์ง€์…˜์„ ์„ ํƒํ•œ๋‹ค
				tmpDatas.add(player); // ์„ ํƒ๋œ ํฌ์ง€์…˜์„ ๋ฐฐ์—ด ์•ˆ์œผ๋กœ ๋„ฃ๋Š”๋‹ค
				System.out.println((i + 1) + ". " + player); // ์„ ํƒ๋œ ํฌ์ง€์…˜ ์ถœ๋ ฅ
				i++;
			}
		}
		buy(tmpDatas);
	}

	public static void printByMainPositionPage() {
		System.out.println("ํฌ์ง€์…˜์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”"); // ํฌ์ง€์…˜ ๋ฒˆํ˜ธ๋กœ ์„ ํƒ
		System.out.println("1. FW");
		System.out.println("2. MF");
		System.out.println("3. DF");
		System.out.println("4. GK");
		System.out.println("0. ์ข…๋ฃŒ");
	}

	// ํฌ์ง€์…˜๋ณ„ ์ถœ๋ ฅ
	public static void printByPosition() { // ์„ ์ˆ˜ ํฌ์ง€์…˜๋ณ„๋กœ ์ถœ๋ ฅํ•˜๊ธฐ
		while (true) {
			printByMainPositionPage(); // ํฌ์ง€์…˜ ์„ ํƒ์ฐฝ
			int action = inputNum("๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", 0, 4); // ํฌ์ง€์…˜ ๋ฒˆํ˜ธ๋กœ ์„ ํƒ
			if (action == 0) {
				System.out.println("ํฌ์ง€์…˜ ์„ ํƒ์„ ๋‚˜๊ฐ‘๋‹ˆ๋‹ค."); // ํฌ์ง€์…˜ ์„ ํƒ ์ข…๋ฃŒ
				break;
			} else {
				String selectedPosition = ""; // ์„ ํƒ๋œ ํฌ์ง€์…˜์„ ์ €์žฅํ•  ๋ณ€์ˆ˜
				// ์„ ํƒ๋œ ํฌ์ง€์…˜ ์„ค์ •
				if (action == 1) {
					selectedPosition = "FW"; // ๋ชจ๋“ˆํ™”๋ฅผ ํ†ตํ•ด ๊ฐ„๋‹จํ•˜๊ฒŒ ํ‘œํ˜„ FW ์„ ํƒ
				} else if (action == 2) {
					selectedPosition = "MF"; // MF ์„ ํƒ
				} else if (action == 3) {
					selectedPosition = "DF";
				} else if (action == 4) {
					selectedPosition = "GK";
				}
				System.out.println(selectedPosition + " ํฌ์ง€์…˜ ์„ ์ˆ˜ ๋ชฉ๋ก"); // ์„ ํƒ๋œ ํฌ์ง€์…˜ ์ถœ๋ ฅ
				printByMainPosition(datas, selectedPosition); // ์„ ์ˆ˜ ์ถœ๋ ฅ
			}
		}
	}

	public static void searchByName() {
		if (!checkListEmpty()) {
			String name = inputString("์„ ์ˆ˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” >> ");
			boolean found = false;
			for (FootballPlayer data : datas) {
				if (data.getName().contains(name)) { // "ํ˜ธ๋‚ ๋‘".contains("ํ˜ธ");
					System.out.println(data);
					found = true;
				}
			}
			if (!found) {
				System.out.println("ํ•ด๋‹น ์ด๋ฆ„์„ ๊ฐ€์ง„ ์„ ์ˆ˜๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.");
			}
		}
	}
	
	// ๋ฒˆํ˜ธ ์ž…๋ ฅ๋ฐ›๊ธฐ ๋ฐ ๋ฒ”์œ„ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ (์ˆ˜์ •, ํ˜„์ง„ => ์˜ค๋ฒ„๋กœ๋”ฉ ์‚ญ์ œ => ๊ฒฐํ•ฉ๋„ ↓, ์‘์ง‘๋„ ↑ => ์ข‹์€ ์ฝ”๋“œ)
	public static int inputNum(String msg, int min, int max) {
		System.out.print(msg);	 // min ์ตœ์†Œ๊ฐ’, max์ตœ๋Œ€๊ฐ’์„ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ ๋ณ€์ˆ˜
		String rangeStr;
		if (min == max) {
			rangeStr = "( " + min + " )";
		} else {
			rangeStr = "(" + min + " ~ " + max + ")";
		}
		System.out.print(rangeStr + " >> ");
		while (true) {
			try {
				int chooseNum = sc.nextInt();
				if (chooseNum >= min && chooseNum <= max) {
					return chooseNum;
				} 
				else if (chooseNum == MANAGERMODE) {
					return chooseNum;
				} 
				else {
					System.out.print(rangeStr + " ์ž…๋ ฅ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. >>");
				}
			} catch (Exception e) {
				System.out.print("'์ •์ˆ˜'๋งŒ ์ž…๋ ฅ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. >>");
				sc.nextLine();
			}
		}
	}

	/*
	 * Main Page
	 */

	public static void printMainPage() {
		System.out.println("=====================");
		System.out.println("โšฝ Football ์ด์  ์‹œ์žฅ โšฝ");
		System.out.println("=====================");
		System.out.println("1. ๊ฐ€๊ฒฉ๋ณ„ ์ถœ๋ ฅ");
		System.out.println("2. ๋Šฅ๋ ฅ์น˜๋ณ„ ์ถœ๋ ฅ");
		System.out.println("3. ํฌ์ง€์…˜๋ณ„ ์ถœ๋ ฅ");
		System.out.println("4. ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ");
		System.out.println("0. ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ");
		System.out.println("======================");
	}

	public static int controller() {
		int select = inputNum("๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” ", 0, 4);
		if (select == 0) {
			System.out.println("ํ”„๋กœ๊ทธ๋žจ์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค..");
		} else if (select == 1) {
			// ๊ฐ€๊ฒฉ๋ณ„ ์ถœ๋ ฅ
			printByPrice();
		} else if (select == 2) {
			// ๋Šฅ๋ ฅ์น˜๋ณ„ ์ถœ๋ ฅ
			printByTotalPower();
		} else if (select == 3) {
			// ํฌ์ง€์…˜๋ณ„ ์ถœ๋ ฅ
			printByPosition();
		} else if (select == 4) {
			// ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ
			searchByName();
		} else if (select == MANAGERMODE) { //231121
			// ๊ด€๋ฆฌ์ž ๋ชจ๋“œ
			execManagerMode();
		} else if (select < 0 || select > 4) {
			// validation ์ฒ˜๋ฆฌ
			System.out.println("์œ ํšจํ•˜์ง€ ์•Š์€ ์ž…๋ ฅ์ž…๋‹ˆ๋‹ค\n๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”\n");
		}
		return select;
	}

	public static void run() {
		while (true) {
			printMainPage();
			int select = controller();
			if (select == 0) {
				break;
			}
		}
	}

	public static void main(String[] args) {

		datas.add(new FootballPlayer(PK++, "ํ˜ธ๋‚ ๋‘", "FW", 89, 8700, 5));
		datas.add(new FootballPlayer(PK++, "๋ฉ”์‹œ", "FW", 91, 8600, 4));
		datas.add(new FootballPlayer(PK++, "์†ํฅ๋ฏผ", "FW", 83, 8300, 7));
		datas.add(new FootballPlayer(PK++, "๊น€๋•๋ฐฐ", "MF", 85, 8500, 2));
		datas.add(new FootballPlayer(PK++, "๋ฐ•์ง€์„ฑ", "MF", 81, 8100, 3));
		datas.add(new FootballPlayer(PK++, "์ด๊ฐ•์ธ", "MF", 77, 7700, 7));
		datas.add(new FootballPlayer(PK++, "์—๋ธŒ๋ผ", "DF", 83, 8300, 6));
		datas.add(new FootballPlayer(PK++, "๊น€๋ฏผ์žฌ", "DF", 79, 7900, 4));
		datas.add(new FootballPlayer(PK++, "๋ง๋””๋‹ˆ", "DF", 84, 8400, 3));
		datas.add(new FootballPlayer(PK++, "์•Œ๋ฒ ์Šค", "DF", 83, 8300, 3));
		datas.add(new FootballPlayer(PK++, "์ด์šด์žฌ", "GK", 83, 8300, 3));

		run();
	
	}
}

โšก ํ›„๊ธฐ

์ฒ˜์Œ์œผ๋กœ ๊ฐ์ž ์—ญํ• ์„ ๋ถ„๋‹ดํ•ด์„œ ์ง„ํ–‰ํ–ˆ๋‹ค. ๋‚˜๋Š” ๊ด€๋ฆฌ์ž๋ชจ๋“œ๋ฅผ ๋‹ด๋‹นํ–ˆ๋Š”๋ฐ ์ƒ๊ฐ๋ณด๋‹ค ์ž‘์„ฑํ•  ์ฝ”๋“œ๊ฐ€ ๋งŽ์•„์„œ ๋‹นํ™ฉํ–ˆ์ง€๋งŒ

์–‘์ด ๋งŽ์€ ๋งŒํผ ์‹ค๋ ฅ์ด ํ–ฅ์ƒ๋  ๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์ž„ํ–ˆ๋‹ค.

๋˜ ๊ฐ์ž ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ํ•˜๋ฉด์„œ ํ”ผ๋“œ๋ฐฑ์„ ํ•˜๋‹ˆ ๊ณ ์ณ์•ผ ํ•  ์ ์„ ๋ฐ”๋กœ๋ฐ”๋กœ ๋А๋‚„ ์ˆ˜ ์žˆ์–ด์„œ ์ข‹์•˜๋‹ค.


 

 

 

๋Œ“๊ธ€

TOP

๋Šฆ์—ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•  ๋• ๋„ˆ๋ฌด ๋Šฆ์€ ๊ฑฐ๋‹ค.