2008년 12월 01일
자바 일기 (프로젝트완성)
import java.io.*;
import java.util.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class NoRaeBang_System extends JFrame implements ActionListener
{
// 화면 사이즈 정보
static final int SCREEN_WIDTH = 640;
static final int SCREEN_HEIGHT = 480;
// 파일 저장 정보
static final String SAVE_FILE = "total.txt";
static final String SAVE_DATA_HEADER = "TOTAL RECORD NUMBER";
static final String SAVE_RECORD_HEADER = "RECORD ID";
// 가격 정보
static final int NORAEBANG_PRICE = 15000;
static final int HELPER_PRICE = 20000;
static final int BEVERAGE_PRICE = 1000;
// 현재 화면 정보
int current_state = -1;
static final int STATE_INIT_ROOM = 0x0100;
static final int STATE_MAIN_SCREEN = 0x0200;
static final int STATE_ENTER_ROOM = 0x0300;
static final int STATE_OUT_OF_ROOM = 0x0400;
static final int STATE_HELPER = 0x0500;
static final int STATE_BEVERAGE = 0x0600;
static final int STATE_ROOM_INFO = 0x0700;
static final int STATE_SALES_INFO = 0x0800;
static final int NEW_SONGS_INFO = 0x0A00;
// 방 정보
int total_room_number = -1;
RoomInfo ri[] = null;
// 메시지 팝업창에서 사용할 변수들
JDialog jpopup = new JDialog(this, "노래방 시스템", true);
JLabel jpopup_label = new JLabel();
JPanel jpopup_panel = new JPanel();
JButton jpopup_button = new JButton("확인");
// 숫자 입력창에서 사용할 변수들
JDialog jinput = new JDialog(this, "노래방 시스템", true);
JLabel jinput_label = new JLabel();
JTextField jinput_textfield = new JTextField();
JButton jinput_button1 = new JButton("확인");
JButton jinput_button2 = new JButton("취소");
// 다이얼로그 화면 정보
int dialog_state = -1;
static final int DG_INPUT_ROOM_NUMBER = 0;
static final int DG_INPUT_ENTER_ROOM = 1;
static final int DG_INPUT_HELPER = 2;
static final int DG_INPUT_BEVERAGE = 3;
// 정보 창에서 사용할 변수들
JDialog jinfo = new JDialog(this, "노래방 시스템", true);
JTextArea jinfo_jta = new JTextArea();
JButton jinfo_button = new JButton("확인");
// 방 정보를 표시하는 화면에서 사용할 변수들
JPanel RoomSelect = null;
JLabel jl_RoomSelect = new JLabel();
JButton jb_RoomSelect[] = new JButton[23];
boolean rs_room_available;
int room_select_page = 0;
int selected_room_idx;
// 메인 메뉴 화면에서 사용할 변수들
JPanel MainScreen = null;
static final String bn_MainScreen[] = {"입 실", "퇴 실", "도우미", "음료수 판매", "방의 정보", "총 매출 확인", "화면 지우기", "신곡 정보", "종 료"};
JButton jb_MainScreen[] = new JButton[bn_MainScreen.length];
JTextArea jta_MainScreen = new JTextArea();
// 세이브 데이터 처리를 위한 HashTable
Hashtable ht = new Hashtable();
public NoRaeBang_System() // 생성자 (변수를 초기화 한다)
{
setTitle("노래방 시스템");
setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loadData(); // 저장한 파일을 읽어온다.
setVisible(true); // 프레임을 화면에 띄운다.
initInputDialog(); // 입력 다이얼로그를 초기화
initInfoDialog(); // 정보 다이얼로그를 초기화
initPopup(); // 팝업 창을 초기화
// 메인 화면에 표시될 정보 입력
jta_MainScreen.setText(" ******************************\n");
jta_MainScreen.append(" * 노래방 관리 프로그램 *\n");
jta_MainScreen.append(" * 만든이 : 박원규 김영철 *\n");
jta_MainScreen.append(" ******************************\n");
jta_MainScreen.append(" \n");
jta_MainScreen.append(" 사용하실 메뉴를 선택해 주세요.\n\n");
setMainScreen(); // 메인 화면을 세팅
setInputDialog("방의 수를 입력해 주세요.", false, DG_INPUT_ROOM_NUMBER);
}
public static void main(String args[]) // 메인 메써드
{
NoRaeBang_System nrb = new NoRaeBang_System();
}
// 이벤트 처리
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == jpopup_button) // 팝업창을 닫는다.
{
jpopup.dispose();
}
else if (evt.getSource() == jinput_button1) // 다이얼로그 확인 버튼 클릭
{
int input_number = -1;
// textfield 에 입력된 값을 읽어온다.
try {
input_number = Integer.parseInt(jinput_textfield.getText());
} catch (Exception e_jb) {}
if (input_number > 0)
{
switch(dialog_state)
{
case DG_INPUT_ROOM_NUMBER: // 방의 수 입력 화면 - 입력된 숫자에 따라 방을 생성하고 각 방을 초기화 한다.
total_room_number = input_number;
ri = new RoomInfo[total_room_number];
for(int i=0;i<total_room_number;i++) ri[i] = new RoomInfo(NORAEBANG_PRICE, HELPER_PRICE, BEVERAGE_PRICE);
initSelectRoom(); // 방 선택 화면 정보를 초기화 한다.
break;
case DG_INPUT_ENTER_ROOM: // 시간 입력
ri[selected_room_idx].enterRoom(input_number);
updateSelectRoom(); // 화면 갱신
updateData(selected_room_idx); // 세이브 데이터 업데이트
setPopupLog((selected_room_idx+1)+" 번 방 사용이 시작되었습니다.");
break;
case DG_INPUT_HELPER: // 도우미 추가
ri[selected_room_idx].addHelper(input_number); // 도우미 추가
updateData(selected_room_idx); // 세이브 데이터 업데이트
setPopupLog((selected_room_idx+1)+" 번 방에 " + input_number + "명의 도우미가 추가되었습니다.");
break;
case DG_INPUT_BEVERAGE: // 음료 추가
ri[selected_room_idx].addBeverage(input_number); // 음료 추가
updateData(selected_room_idx); // 세이브 데이터 업데이트
setPopupLog((selected_room_idx+1)+" 번 방에 " + input_number + "개의 음료가 추가되었습니다.");
break;
}
jinput.dispose(); // 다이얼로그 창을 닫는다.
}
else
setPopup("숫자를 올바르게 입력해 주세요.");
}
else if (evt.getSource() == jinput_button2) // 다이얼로그 취소 버튼 클릭
{
jinput.dispose(); // 다이얼로그 창을 닫는다.
}
else if (evt.getSource() == jinfo_button) // 방 정보 다이얼로그 확인 클릭
{
jinfo.dispose(); // 다이얼로그 창을 닫는다.
}
else
{
// 메인 화면에 있는 버튼을 처리
for(int i=0;i<jb_MainScreen.length;i++)
{
if (evt.getSource() == jb_MainScreen[i]) event_MainScreen(i);
}
// 방선택 이벤트 처리
for(int i=0;i<jb_RoomSelect.length;i++)
{
if (evt.getSource() == jb_RoomSelect[i]) event_RoomSelect(i);
}
}
}
// 메인화면의 버튼 처리
public void event_MainScreen(int idx)
{
switch(idx)
{
case 0: // 입실
room_select_page = 0;
setEnterRoom();
break;
case 1: // 퇴실
room_select_page = 0;
setOutofRoom();
break;
case 2: // 도우미
room_select_page = 0;
setHelper();
break;
case 3: // 음료수
room_select_page = 0;
setBeverage();
break;
case 4: // 방정보
room_select_page = 0;
setRoomInfo();
break;
case 5: // 총 매출 확인
setInfoDialog();
break;
case 6:
jta_MainScreen.setText(" 사용하실 메뉴를 선택해 주세요.\n\n");
break;
case 7: // 신곡 정보
break;
case 8:
System.exit(0);
break;
}
}
// 방 선택시 이벤트 처리
public void event_RoomSelect(int idx)
{
switch(idx)
{
case 20: // 이전 페이지
room_select_page = Math.max(0, room_select_page-1);
updateSelectRoom();
break;
case 21: // 다음 페이지
room_select_page = Math.min((total_room_number-1)/20, room_select_page+1);
updateSelectRoom();
break;
case 22: // 메인 화면
setMainScreen();
break;
default: // 각 방을 선택한 경우
selected_room_idx = room_select_page * 20 + idx; // 해당 방의 실제 인덱스를 구한다.
switch(current_state)
{
case STATE_ENTER_ROOM:
setInputDialog("몇 시간을 사용하실 건가요?", true, DG_INPUT_ENTER_ROOM);
break;
case STATE_OUT_OF_ROOM:
ri[selected_room_idx].outofRoom();
updateSelectRoom();
setPopupLog((selected_room_idx+1)+" 번 방의 사용이 종료되었습니다.");
break;
case STATE_HELPER:
setInputDialog("몇명의 도우미를 추가하실 건가요?", true, DG_INPUT_HELPER);
break;
case STATE_BEVERAGE:
setInputDialog("몇개의 음료를추가하실 건가요?", true, DG_INPUT_BEVERAGE);
break;
case STATE_ROOM_INFO:
setInfoDialog(selected_room_idx);
break;
}
break;
}
}
// 팝업 다이얼로그 창 초기화
public void initPopup()
{
jpopup.setSize(300,135); //크기
//jpopup.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
Dimension screen = this.getSize(); //화면크기
Dimension frame = jpopup.getSize(); //다이얼로그 크기
jpopup.setLocation( (int)(screen.getWidth()-frame.getWidth())/2 , (int)(screen.getHeight()-frame.getHeight())/2 );
jpopup.setLayout(new BorderLayout());
jpopup.add(jpopup_label);
jpopup_panel.add("Center", jpopup_button);
jpopup.add("South", jpopup_panel);
jpopup_label.setHorizontalAlignment(JLabel.CENTER);
jpopup_button.addActionListener(this);
}
// 메인 화면에 text 를 추가하고 팝업을 띄운다.
public void setPopupLog(String s)
{
jta_MainScreen.append(s+"\n");
setPopup(s);
}
// 팝업 창에 메시지를 설정하고 화면에 띄운다.
public void setPopup(String s)
{
jpopup_label.setText(s);
jpopup.setVisible(true);
}
// 숫자 입력 다이얼로그를 초기화 한다.
public void initInputDialog()
{
jinput.setSize(300, 135);
jinput.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// 다이얼로그를 화면 중간에 배치하기 위한 코드
Dimension screen = this.getSize(); // 화면크기를 얻어옴
Dimension frame = jinput.getSize(); // 다이얼로그 크기를 얻어옴
int pos_x = (int) (screen.getWidth() / 2 - frame.getWidth() / 2);
int pos_y = (int) (screen.getHeight() / 2 - frame.getHeight() / 2);
jinput.setLocation(pos_x, pos_y); // 다이얼로그 위치 지정
// 다이얼로그에 필요한 내용을 추가하는 코드
jinput.setLayout(null);
jinput_label.setHorizontalAlignment(JLabel.CENTER);
jinput_label.setBounds(0, 10, 300, 20);
jinput_textfield.setBounds(20, 40, 255, 20);
jinput_button2.setBounds(115+40, 75, 62, 28);
jinput_button1.addActionListener(this);
jinput_button2.addActionListener(this);
jinput.add(jinput_label);
jinput.add(jinput_textfield);
jinput.add(jinput_button1);
jinput.add(jinput_button2);
}
// 숫자 입력 다이얼로그를 띄운다.
public void setInputDialog(String tf, boolean clr, int dg_idx)
{
dialog_state = dg_idx;
jinput_label.setText(tf);
jinput_textfield.setText(null);
if (clr)
jinput_button1.setBounds(115-40, 75, 62, 28);
else
jinput_button1.setBounds(115, 75, 62, 28);
jinput_button2.setVisible(clr);
jinput.setVisible(true);
}
// 정보 창 초기화
public void initInfoDialog()
{
jinfo.setSize(300, 235);
jinfo.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// 다이얼로그를 화면 중간에 배치하기 위한 코드
Dimension screen = this.getSize(); // 화면크기를 얻어옴
Dimension frame = jinfo.getSize(); // 다이얼로그 크기를 얻어옴
int pos_x = (int) (screen.getWidth() / 2 - frame.getWidth() / 2);
int pos_y = (int) (screen.getHeight() / 2 - frame.getHeight() / 2);
jinfo.setLocation(pos_x, pos_y); // 다이얼로그 위치 지정
// 다이얼로그에 필요한 내용을 추가하는 코드
jinfo.setLayout(null);
jinfo_jta.setBounds(10, 10, 272, 160);
//jinfo_jta.setEnabled(false);
jinfo.add(jinfo_jta);
jinfo_button.setBounds(115, 175, 62, 28);
jinfo_button.addActionListener(this);
jinfo.add(jinfo_button);
}
// 방 정보 창을 띄운다.
public void setInfoDialog(int rn)
{
int sub[] = new int[3];
for(int i=0;i<3;i++)
{
sub[i] = ri[rn].sd.sdata[i][0] * ri[rn].sd.sdata[i][1];
}
jinfo_jta.setText("방사용료\n");
jinfo_jta.append(" "+ri[rn].sd.sdata[0][0] + " x " + ri[rn].sd.sdata[0][1] + " = \t" + sub[0] + "\n");
jinfo_jta.append("도우미\n");
jinfo_jta.append(" "+ri[rn].sd.sdata[1][0] + " x " + ri[rn].sd.sdata[1][1] + " = \t" + sub[1] + "\n");
jinfo_jta.append("음료\n");
jinfo_jta.append(" "+ri[rn].sd.sdata[2][0] + " x " + ri[rn].sd.sdata[2][1] + " = \t" + sub[2] + "\n");
jinfo_jta.append("\n합계\n");
jinfo_jta.append(" \t\t"+(sub[0]+sub[1]+sub[2]));
jinfo.setVisible(true);
}
// 총 매출 정보 창을 띄운다.
public void setInfoDialog()
{
int sub[] = new int[3];
for (Enumeration e = ht.elements() ; e.hasMoreElements() ;) {
SalesData sd = (SalesData)e.nextElement();
for(int i=0;i<3;i++)
{
sub[i] += sd.sdata[i][0] * sd.sdata[i][1];
}
}
jinfo_jta.setText("방사용료\n");
jinfo_jta.append(" \t\t" + sub[0] + "\n");
jinfo_jta.append("도우미\n");
jinfo_jta.append(" \t\t" + sub[1] + "\n");
jinfo_jta.append("음료\n");
jinfo_jta.append(" \t\t" + sub[2] + "\n");
jinfo_jta.append("\n합계\n");
jinfo_jta.append(" \t\t"+(sub[0]+sub[1]+sub[2]));
jinfo.setVisible(true);
}
// 방 선택 부분 UI 초기화
public void initSelectRoom()
{
if (RoomSelect == null)
{
RoomSelect = new JPanel();
RoomSelect.setLayout(null);
jl_RoomSelect.setBounds(10, 10, SCREEN_WIDTH, 30);
RoomSelect.add(jl_RoomSelect);
jb_RoomSelect[20] = new JButton("이전 페이지");
jb_RoomSelect[20].setBounds(SCREEN_WIDTH-300, SCREEN_HEIGHT-60, 128, 28);
jb_RoomSelect[20].addActionListener(this);
jb_RoomSelect[21] = new JButton("다음 페이지");
jb_RoomSelect[21].setBounds(SCREEN_WIDTH-150, SCREEN_HEIGHT-60, 128, 28);
jb_RoomSelect[21].addActionListener(this);
jb_RoomSelect[22] = new JButton("메인 메뉴");
jb_RoomSelect[22].setBounds(SCREEN_WIDTH-150, 10, 128, 28);
jb_RoomSelect[22].addActionListener(this);
RoomSelect.add(jb_RoomSelect[20]);
RoomSelect.add(jb_RoomSelect[21]);
RoomSelect.add(jb_RoomSelect[22]);
int wspan = (SCREEN_WIDTH-27)/5 -1;
int hspan = (SCREEN_HEIGHT-115)/4 -1;
for(int i=0;i<20;i++)
{
jb_RoomSelect[i] = new JButton("");
jb_RoomSelect[i].setBounds(10 + (wspan+1)*(i%5), 45 + (hspan+1)*(i/5), wspan, hspan);
jb_RoomSelect[i].addActionListener(this);
RoomSelect.add(jb_RoomSelect[i]);
}
}
}
// 방 선택 세팅 : 빈방이 선택될때도 있고, 사람이 있는 방이 선택될 수도 있기 때문에 rs_room_available을 플래그로 넣는다.
public void setSelectRoom(String title, boolean room_status)
{
jl_RoomSelect.setText(title);
rs_room_available = room_status;
updateSelectRoom();
}
// 방 선택 부분 화면 업데이트 처리
public void updateSelectRoom()
{
jb_RoomSelect[20].setEnabled(room_select_page > 0);
jb_RoomSelect[21].setEnabled(room_select_page < (total_room_number - 1)/20);
for(int i=0;i<20;i++)
{
jb_RoomSelect[i].setText( (room_select_page * 20 + 1 + i) + "번 방" );
if (room_select_page * 20 + i < total_room_number)
{
jb_RoomSelect[i].setVisible(true);
jb_RoomSelect[i].setEnabled( rs_room_available^ri[room_select_page * 20 + i].room_available );
} else jb_RoomSelect[i].setVisible(false);
}
}
// 기존 패널을 프레임에서 제거해 주는 매써드
public void removePreviousScreen()
{
switch(current_state)
{
case STATE_MAIN_SCREEN: remove(MainScreen); break;
case STATE_ENTER_ROOM:
case STATE_OUT_OF_ROOM:
case STATE_HELPER:
case STATE_BEVERAGE:
case STATE_ROOM_INFO: remove(RoomSelect); break;
}
}
// 메인 화면 꾸며주는 메써드
public void setMainScreen()
{
if (current_state > 0) removePreviousScreen();
if (MainScreen == null)
{
MainScreen = new JPanel();
MainScreen.setLayout(null);
int num_button = bn_MainScreen.length;
int span = (SCREEN_HEIGHT - 45 - 2 * num_button) / num_button + 2;
for(int i=0;i<num_button;i++)
{
jb_MainScreen[i] = new JButton(bn_MainScreen[i]);
jb_MainScreen[i].setBounds(10, 10+span*i, SCREEN_WIDTH/4-11, span-2);
jb_MainScreen[i].addActionListener(this);
MainScreen.add(jb_MainScreen[i]);
}
jta_MainScreen.setBorder(new LineBorder(Color.GRAY));
jta_MainScreen.setBounds(10+SCREEN_WIDTH/4, 10, SCREEN_WIDTH*3/4-26, span*num_button-2);
//jta_MainScreen.setEnabled(false);
MainScreen.add(jta_MainScreen);
}
add(MainScreen);
setVisible(true);
repaint();
current_state = STATE_MAIN_SCREEN;
}
// 입실
public void setEnterRoom()
{
if (current_state > 0) removePreviousScreen();
setSelectRoom("입실할 방을 선택해 주세요", false); // 사용가능한 방을 체크
add(RoomSelect);
setVisible(true);
repaint();
current_state = STATE_ENTER_ROOM;
}
// 퇴실
public void setOutofRoom()
{
if (current_state > 0) removePreviousScreen();
setSelectRoom("퇴실할 방을 선택해 주세요", true); // 사용 중인 방을 체크
add(RoomSelect);
setVisible(true);
repaint();
current_state = STATE_OUT_OF_ROOM;
}
// 도우미 추가
public void setHelper()
{
if (current_state > 0) removePreviousScreen();
setSelectRoom("도우미를 추가할 방을 선택해 주세요.", true); // 사용 중인 방을 체크
add(RoomSelect);
setVisible(true);
repaint();
current_state = STATE_HELPER;
}
// 음료수 추가
public void setBeverage()
{
if (current_state > 0) removePreviousScreen();
setSelectRoom("음료수를 주문한 방을 선택해 주세요.", true); // 사용 중인 방을 체크
add(RoomSelect);
setVisible(true);
repaint();
current_state = STATE_BEVERAGE;
}
// 방 정보 보기
public void setRoomInfo()
{
if (current_state > 0) removePreviousScreen();
setSelectRoom("정보를 확인할 방을 선택해 주세요.", true); // 사용 중인 방을 체크
add(RoomSelect);
setVisible(true);
repaint();
current_state = STATE_ROOM_INFO;
}
// hex 데이터를 long 데이터로 바꿔주는 매써드
public long getLong(String h)
{
String t = h.toLowerCase();
long rv = 0l;
for(int i=0;i<t.length();i++)
{
if (t.charAt(i) <= '9')
{
rv = (rv << 4) | (t.charAt(i)-'0');
}
else
{
rv = (rv << 4) | (t.charAt(i)-'a'+10);
}
}
return rv;
}
// HashTable 에 저장된 데이터를 업데이트 하고 파일에 기록한다.
public void updateData(int rn)
{
// HashTable 에서 같은 키 값이 존재하는지 체크해서 있으면 삭제
if (ht.containsKey(ri[rn].sd.start_time))
{
ht.remove(ri[rn].sd.start_time);
}
// HashTable에 등록한다.
ht.put(ri[rn].sd.start_time, ri[rn].sd);
saveData();
}
// 파일에 저장하는 매써드
public void saveData()
{
try {
PrintWriter pw = new PrintWriter(SAVE_FILE);
pw.println(SAVE_DATA_HEADER+" : "+ht.size()); // 파일에 데이터 개수를 저장
pw.println("-------------------------------"); //
int g_total = 0;
for (Enumeration e = ht.elements() ; e.hasMoreElements() ;) { // HashTable의 객체들을 읽어옴
SalesData sd = (SalesData)e.nextElement();
int sub[] = new int[3];
int sub_total = 0;
for(int i=0;i<3;i++)
{
sub[i] = sd.sdata[i][0] * sd.sdata[i][1];
sub_total += sub[i];
}
g_total += sub_total;
pw.println(SAVE_RECORD_HEADER+" : "+Long.toHexString(sd.start_time)); // HashTable에 저장된 키값
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
Date nnn = new Date(sd.start_time);
pw.println("Time : " + formatter.format(nnn)); // 날짜를 기록한다.
pw.println("방사용료");
pw.println("\t"+sd.sdata[0][0]+" x "+sd.sdata[0][1] + " =\t" + sub[0]);
pw.println("도우미");
pw.println("\t"+sd.sdata[1][0]+" x "+sd.sdata[1][1] + " =\t" + sub[1]);
pw.println("음료수");
pw.println("\t"+sd.sdata[2][0]+" x "+sd.sdata[2][1] + " =\t" + sub[2]);
pw.println("합계\t\t\t" + sub_total);
pw.println("-------------------------------");
}
pw.println("총합계\t\t\t" + g_total);
pw.flush();
pw.close();
} catch (Exception err) {}
}
// 저장된 파일을 읽어온다.
// 처음에 헤더를 읽어서 데이터 개수를 읽고,
// 나머지는 해당 데이터들을 파싱해서 처리한다.
public void loadData()
{
try {
FileReader fr = new FileReader(SAVE_FILE);
BufferedReader br = new BufferedReader(fr);
int data_num = 0;
int counter = 0;
while(true)
{
String line = br.readLine();
if (line == null) break;
if (data_num == 0)
{
if (line.indexOf(SAVE_DATA_HEADER) > -1)
{
data_num = Integer.parseInt(line.substring(line.indexOf(":")+1).trim());
}
}
else
{
// 새로운 레코드의 시작
if (line.indexOf(SAVE_RECORD_HEADER) > -1)
{
SalesData sd = new SalesData();
// 키 값을 읽어온다.
sd.start_time = getLong(line.substring(line.indexOf(":")+1).trim());
line = br.readLine();
// 수량 과 단가를 읽어온다.
for(int i=0;i<3;i++)
{
line = br.readLine();
line = br.readLine().trim();
sd.sdata[i][0] = Integer.parseInt(line.substring(0, line.indexOf("x")).trim());
sd.sdata[i][1] = Integer.parseInt(line.substring(line.indexOf("x")+1, line.indexOf("=")).trim());
}
// HashTable에 저장한다.
ht.put(sd.start_time, sd);
counter ++;
if (counter == data_num) break;
}
}
}
br.close();
fr.close();
} catch (Exception e) {}
}
}
// 세이브 데이터로 사용될 데이터 객체
class SalesData
{
long start_time; // 방 사용 시작 시간
int sdata[][] = new int[3][2]; // 사용시간, 요금, 도우미, 요금, 음료수, 요금
}
// 방 정보에 해당하는 객체
class RoomInfo
{
boolean room_available = true; // 방이 비었는지 여부
SalesData sd = new SalesData();
// 방 객체를 생성할 때, 가격 정보를 기록한다.
public RoomInfo(int c1, int c2, int c3)
{
sd.sdata[0][1] = c1;
sd.sdata[1][1] = c2;
sd.sdata[2][1] = c3;
}
// 입실을 처리한다.
// 입실시 시간을 기록하는데, 이 시간은 HashTable의 키로 사용된다.
public void enterRoom(int t)
{
room_available = false;
sd.start_time = System.currentTimeMillis();
sd.sdata[0][0] = t;
}
// 퇴실 처리
public void outofRoom()
{
room_available = true;
for (int i=0;i<sd.sdata.length;i++) sd.sdata[i][0] = 0;
}
// 도우미 추가
public void addHelper(int num)
{
sd.sdata[1][0] += num;
}
// 음료 추가
public void addBeverage(int num)
{
sd.sdata[2][0] += num;
}
}
이렇게 프로젝트가 완성 되었네여 ㅎㅎ
제가 모자른 부분이 많아서 같은조 형한테 도움을 많이 받았습니다.
그래도 뿌듯하네여 ㅎㅎ
그럼 과제 발표 때 뵙겠씁니다.
# by | 2008/12/01 21:27 | 실험프로젝트2학기 | 트랙백 | 덧글(1)





☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]