ํ•ญ๊ณต๊ธฐ

 

โŠ™ AmsField

package ams;

public class AmsField {
	//				Key
	// ํ•ญ๊ณต์‚ฌ, ํ•ญ๊ณต๊ธฐ๋ฒˆํ˜ธ, ์ตœ๋Œ€์Šน๊ฐ์ˆ˜, ์ถœ๋ฐœ์ง€, ๋„์ฐฉ์ง€
	String[][] arrPlane = new String[100][5];
	int insertCnt;
	int updateIndex;

	// ์ถ”๊ฐ€
	// 2์ฐจ์› ๋ฐฐ์—ด์— 5๊ฐœ์˜ ์ •๋ณด๋ฅผ ๋‹ด๊ธฐ
	void insert(String[] arPlane) {
		arrPlane[insertCnt] = arPlane;
		insertCnt++;
	}

	// ์ˆ˜์ •
	void update(int index, String newValue) {
		boolean updateCheck = true;
		//ํ•ญ๊ณต์‚ฌ, ํ•ญ๊ณต๊ธฐ๋ฒˆํ˜ธ, ์Šน๊ฐ์ˆ˜, ์ถœ๋ฐœ์ง€, ๋„์ฐฉ์ง€
		//0			1				2			3			4
		//index : 0, 1
			arrPlane[updateIndex][index+3] = newValue;
	}

	// ์‚ญ์ œ
	void delete() {
	}

	// ๊ฒ€์ƒ‰
	String select(int index, String keyword) {
		int[] arIndex = null;
		int searchCnt = 0;
		String result = "";
		updateIndex = -1;
		
		for (int i = 0; i < insertCnt; i++) {
			if (keyword.equals(arrPlane[i][index])) {
				// i >> ํ–‰๋ฒˆํ˜ธ : ๊ฒ€์ƒ‰ํ•  ๋น„ํ–‰๊ธฐ ๋ฒˆํ˜ธ
				searchCnt++;
				updateIndex = i;
				//๋ฐ”๋กœ int๋ฐฐ์—ด์— ๋‹ด์„ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์—(๊ฒ€์ƒ‰ ๊ฑด์ˆ˜๋ฅผ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ)
				//๋ฌธ์ž์—ด์— ๊ฒ€์ƒ‰๋œ ํ–‰๋ฒˆํ˜ธ๋ฅผ ์—ฐ๊ฒฐ์‹œ์ผœ ๋‹ด๋Š”๋‹ค.(", "๋Š” ๊ตฌ๋ถ„์ ์ด๋‹ค.)
				//๊ตฌ๋ถ„์ ์ด ์žˆ์–ด์•ผ์ง€๋งŒ ๋ฐ‘์—์„œ ๊ฐ ๊ฐ’์„ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
				result += i + ", ";
			}
		}
		//๊ฒ€์ƒ‰ ๊ฑด์ˆ˜๋ฅผ for๋ฌธ์ด ๋๋‚œ ํ›„์— ์•Œ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—
		//for๋ฌธ ๋ฐ‘์—์„œ new ํ•ด์ค€๋‹ค.
		arIndex = new int[searchCnt];
		for (int i = 0; i < arIndex.length; i++) {
			//	result๋Š” ๋ฌธ์ž์—ด์ด๊ณ  split() ์‚ฌ์šฉ์‹œ 
			//์ „์ฒด๋ฅผ ๋ฐฐ์—ด๋กœ ๋ณด๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ ๋’ค์— ๋ฐ”๋กœ []๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
			arIndex[i] = Integer.parseInt(result.split(", ")[i]);
		}
		//list(int[] arIndex)๋ฉ”์„œ๋“œ์— ๊ฐ’์„ ์ „๋‹ฌํ•˜๊ณ  list(int[] arIndex)์—์„œ ๋ฆฌํ„ด๋œ
		//๊ฒฐ๊ณผ๊ฐ’์„ select()์—์„œ ๋ฆฌํ„ดํ•œ๋‹ค.
		return list(arIndex);
	}

	// ๋ชฉ๋ก
	String list() {
		String result = "ํ•ญ๊ณต์‚ฌ, ํ•ญ๊ณต๊ธฐ๋ฒˆํ˜ธ, ์ตœ๋Œ€์Šน๊ฐ์ˆ˜(๋ช…), ์ถœ๋ฐœ์ง€, ๋„์ฐฉ์ง€\n";
		for (int i = 0; i < insertCnt; i++) {
			result += "♥";
			for (int j = 0; j < arrPlane[0].length; j++) {
				result += arrPlane[i][j];
				result += j == arrPlane[0].length - 1 ? "" : ", ";
			}
			result += "\n";
		}

		if (insertCnt == 0)
			result = "๋ชฉ๋ก ์—†์Œ";

		return result;
	}
	
	String list(int[] arIndex) {
		String result = "ํ•ญ๊ณต์‚ฌ, ํ•ญ๊ณต๊ธฐ๋ฒˆํ˜ธ, ์ตœ๋Œ€์Šน๊ฐ์ˆ˜(๋ช…), ์ถœ๋ฐœ์ง€, ๋„์ฐฉ์ง€\n";
		for (int i = 0; i < arIndex.length; i++) {
			result += "♥";
			for (int j = 0; j < arrPlane[0].length; j++) {
				result += arrPlane[arIndex[i]][j];
				result += j == arrPlane[0].length - 1 ? "" : ", ";
			}
			result += "\n";
		}

		if (arIndex.length == 0)
			result = "๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์—†์Œ";

		return result;
	}
	
}

 


 

โŠ™ AmsMain

package ams;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class AmsMain {
	public static void main(String[] args) {
		String title = "ํ•ญ๊ณต๊ธฐ ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ";
		String[] menu = {"์ถ”๊ฐ€ํ•˜๊ธฐ", "๊ฒ€์ƒ‰ํ•˜๊ธฐ", "์ˆ˜์ •ํ•˜๊ธฐ", "์‚ญ์ œํ•˜๊ธฐ", "๋ชฉ๋ก๋ณด๊ธฐ"};
		String[] updateMenu = {"์ถœ๋ฐœ์ง€ ์ˆ˜์ •", "๋„์ฐฉ์ง€ ์ˆ˜์ •"};
		String[] updateMsg = {"์ถœ๋ฐœ์ง€", "๋„์ฐฉ์ง€"};
		AmsField af = new AmsField();
		ImageIcon icon = new ImageIcon("src/img/main.gif");
		int choice = 0;
		String[] arPlane = new String[5];
		String keyword = "";
		
		while(true) {
			choice = JOptionPane.showOptionDialog(null, "", title, JOptionPane.DEFAULT_OPTION,
					JOptionPane.PLAIN_MESSAGE, icon, menu, null);
			
			if(choice == -1) break;
			
			switch(choice) {
			//์ถ”๊ฐ€
			//ํ•ญ๊ณต์‚ฌ, ํ•ญ๊ณต๊ธฐ๋ฒˆํ˜ธ, ์ตœ๋Œ€์Šน๊ฐ์ˆ˜(๋ช…), ์ถœ๋ฐœ์ง€, ๋„์ฐฉ์ง€
			case 0:
				//5๊ฐœ์˜ ๊ฐ’์„ ", "๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•œ๋ฒˆ์— ์ž…๋ ฅํ•˜๊ธฐ
				//split("๊ตฌ๋ถ„์ ")์€ ๋ฆฌํ„ดํƒ€์ž…์ด ๋ฌธ์ž์—ด ๋ฐฐ์—ด์ด๋‹ค.
				//๊ตฌ๋ถ„์ ์ด ์žˆ๋‹ค๋Š” ๊ฒƒ์€ ์ตœ์†Œํ•œ ๊ฐ’์ด 2๊ฐœ ์ด์ƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐฐ์—ด๋กœ ๋ฆฌํ„ดํ•œ๋‹ค.
				arPlane = ("" + JOptionPane.showInputDialog(null,
						"ํ•ญ๊ณต์‚ฌ, ํ•ญ๊ณต๊ธฐ๋ฒˆํ˜ธ, ์ตœ๋Œ€์Šน๊ฐ์ˆ˜(๋ช…), ์ถœ๋ฐœ์ง€, ๋„์ฐฉ์ง€", title, JOptionPane.PLAIN_MESSAGE,
						icon,	null, null)).split(", ");
				
				af.insert(arPlane);
				break;
			//๊ฒ€์ƒ‰
			case 1:
				break;
			//์ˆ˜์ •
			case 2:
				String newValue = "";
				
				choice =JOptionPane.showOptionDialog(null, "", title, JOptionPane.DEFAULT_OPTION,
						JOptionPane.PLAIN_MESSAGE, icon, updateMenu, null);
				
				if(choice == -1) break;
				
				keyword = "" + JOptionPane.showInputDialog(null,
						"์ˆ˜์ •ํ•˜์‹ค ํ•ญ๊ณต๊ธฐ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”", title, JOptionPane.PLAIN_MESSAGE,
						icon,	null, null);
				
				if(af.select(1, keyword).equals("๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์—†์Œ")) {
					JOptionPane.showMessageDialog(null, "์ˆ˜์ • ์‹คํŒจ");
				}else {
					newValue = "" + JOptionPane.showInputDialog(null,
							"์ƒˆ๋กœ์šด " + updateMsg[choice] + "๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”", title, JOptionPane.PLAIN_MESSAGE,
							icon,	null, null);
					af.update(choice, newValue);
					JOptionPane.showMessageDialog(null, "์ˆ˜์ • ์„ฑ๊ณต");
				}
				
				break;
			//์‚ญ์ œ
			case 3:
				break;
			//๋ชฉ๋ก
			case 4:
				JOptionPane.showMessageDialog(null, af.list());
				break;
			}
		}
	}
}

 

+ Recent posts