URGENT!! all the JAVA EXPERTS plssss help me!!
thanks for replying me....i m actually doing a coursework that i have to submit by next monday 29/4/2002. and i havent finish it yet.... ok .. finally i have finish level 1, now i m doing level two...
my program in level 2 should :
a.) Allow the user to specify certain criteria for a room that they wish to book on a particular day. e.g. X number of people, video conferencing, your program should find an appropriate room for them that is free on that day.
b.) Allow the user to add more rooms to the system and make these available to the user to book.
c.) Allow a user to attempt to delete a room. The room will only be deleted if it has no bookings.
d.) Allow the user to ask the system to find the minimum fit room free e.g.
* the smallest room to hold X people that has a connection to the internet.
* if the user requests a room for 40 people and there are rooms free for 50 and 60 people, then
it will allocate them the room for 50.
i really donno how to do....pls help me....
there is something wrong in the METHOD --> AddDeleteRoom()
and i donno how to code the AddNewRoom()
i need to add more rooms into my array
u can download these coding .....i got three files, 1 is the main class call CC.java, another 1 is the class filewhich is Rooms.java and the third file is CC.html file.
dont worry, u can save all the coding in here.... i try b4 it can run.....
<<save as CC.java>>
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.JApplet;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
public class CC extends JApplet implements ActionListener,ItemListener
{
JPanel pnlPane = new JPanel();
JPanel pnlChoise = new JPanel();
JPanel pnlButton2 = new JPanel();
JPanel pnlRoomDisplay = new JPanel();
JPanel pnlRoom = new JPanel();
JPanel pnlDisplay = new JPanel();
JPanel pnlClear = new JPanel();
JButton btnDisplay = new JButton("Display");
JButton btnBookRoom = new JButton("Book Room");
JButton btnDelBookRoom = new JButton("Delete Booking");
JButton btnDelRoom = new JButton("Delete Room");
JButton btnAddNewRoom = new JButton("Add New Room");
JButton btnClear = new JButton("Clear");
JButton btnRoomQuery = new JButton("Room Query");
Rooms []room = new Rooms[11];
String[] Days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int [][] book = new int[11][7];
public int R, D;
JLabel lblRoomName = new JLabel();
JLabel lblCapacity = new JLabel();
JLabel lblInternet = new JLabel();
JLabel lblVideo = new JLabel();
JLabel lblStatus = new JLabel();
JComboBox cDays= new JComboBox(Days);
JComboBox cRooms = new JComboBox();
JTextField txtRoomName1 = new JTextField();
JTextField txtCapacity1 = new JTextField();
JCheckBox chkInternet = new JCheckBox("Internet Connection");
JCheckBox chkVideo = new JCheckBox("Video Conferencing");
JTextArea txtDisplay = new JTextArea("*****Rooms Detail*****" + "\n",12,30);
public void init()
{
pnlPane.add(pnlChoise);
pnlPane.add(pnlButton2);
pnlPane.add(pnlRoomDisplay);
pnlPane.add(pnlRoom);
pnlPane.add(pnlDisplay);
pnlPane.add(pnlClear);
pnlPane.setBorder(new TitledBorder(new BevelBorder(BevelBorder.RAISED),"Room Booking System"));
setContentPane(pnlPane);
AddChoisePanel();
AddButton2Panel();
AddRoomDisplayPanel();
AddRoomPanel();
AddDisplayAreaPanel();
AddClearPanel();
}
public void AddChoisePanel()
{
pnlChoise.setLayout(new GridLayout(1,3,5,5));
room[0]=new Rooms("Barrington","15","No","Yes");
room[1]=new Rooms("Carlton","25","Yes","No");
room[2]=new Rooms("Debyshire","35","No","No");
room[3]=new Rooms("Edwards","30","Yes","Yes");
room[4]=new Rooms("Farley","70","Yes","No");
room[5]=new Rooms("Goodwin","80","Yes","Yes");
room[6]=new Rooms("Harlow","90","No","Yes");
room[7]=new Rooms("IlFord","85","No","No");
for (int i=0; i<8; i++)
cRooms.addItem(room.rName);
pnlChoise.add(cRooms);
pnlChoise.add(cDays);
pnlChoise.add(btnRoomQuery);
btnRoomQuery.addActionListener(this);
cRooms.addItemListener(this);
}
public void AddButton2Panel()
{
pnlButton2.setLayout(new GridLayout(1,2,5,5));
pnlButton2.add(btnBookRoom);
pnlButton2.add(btnDelBookRoom);
btnDelBookRoom.addActionListener(this);
btnBookRoom.addActionListener(this);
}
public void AddRoomDisplayPanel()
{
pnlRoomDisplay.setLayout(new GridLayout(6,2,5,2));
pnlRoomDisplay.add(new JLabel("Room Name" ));
pnlRoomDisplay.add(lblRoomName);
pnlRoomDisplay.add(new JLabel("Room Capacity"));
pnlRoomDisplay.add(lblCapacity);
pnlRoomDisplay.add(new JLabel("Internet Connection"));
pnlRoomDisplay.add(lblInternet);
pnlRoomDisplay.add(new JLabel("Video Conferencing"));
pnlRoomDisplay.add(lblVideo);
pnlRoomDisplay.add(new JLabel("Room Status"));
pnlRoomDisplay.add(lblStatus);
pnlRoomDisplay.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED),"Rooms Detail"));
pnlRoomDisplay.add(btnDelRoom);
btnDelRoom.addActionListener(this);
}
public void AddRoomPanel()
{
pnlRoom.setLayout(new GridLayout(6,2,2,2));
pnlRoom.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED),"Add New Rooms"));
pnlRoom.add(new Label("Room Name"));
pnlRoom.add(txtRoomName1);
pnlRoom.add(new Label("Capacity"));
pnlRoom.add(txtCapacity1);
pnlRoom.add(chkInternet);
pnlRoom.add(new Label(""));
pnlRoom.add(chkVideo);
pnlRoom.add(new Label(""));
pnlRoom.add(new Label(""));
pnlRoom.add(new Label(""));
pnlRoom.add(btnAddNewRoom);
btnAddNewRoom.addActionListener(this);
}
public void AddDisplayAreaPanel()
{
pnlDisplay.setLayout(new GridLayout(1,1));
//pnlDisplay.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED),"Rooms Detail"));
Border pnlDisplayBorder = BorderFactory.createTitledBorder("Rooms Detail");
pnlDisplay.setBorder(pnlDisplayBorder);
pnlDisplay.add(txtDisplay);
}
public void AddClearPanel()
{
pnlClear.setLayout(new GridLayout(1,1));
pnlClear.add(btnClear);
btnClear.addActionListener(this);
}
public void actionPerformed(ActionEvent event)
{
//to call RoomQuery function
if (event.getSource() == btnRoomQuery){
AddRoomQuery(); }
else
{
//to call DeleteBookRoom function
if (event.getSource() == btnDelBookRoom){
AddDeleteBookRoom(); }
else
{
//to call DeleteRoom function
if (event.getSource() == btnDelRoom){
AddDeleteRoom(); }
else
{
//to call AddNewRoom function
if (event.getSource() == btnAddNewRoom){
AddNewRoom(); }
else
{
//to call ClearTextArea function
if (event.getSource() == btnClear){
AddClearTextArea(); }
else
{
//to call BookRoom function
if (event.getSource() == btnBookRoom){
AddBookRoom(); }
}
}
}
}
}
}
public void AddRoomQuery()
{
R= (int) cRooms.getSelectedIndex();
D = (int) cDays.getSelectedIndex();
JOptionPane.showMessageDialog(null, R + " " + D);
txtDisplay.setText(" *************** Room Status For "+ Days[D] + " *************** " + "\n");
txtDisplay.append("Rooms" + "\t\t " + " Status");
for (int t=0; t< (int) cRooms.getItemCount(); t++)
{ JOptionPane.showMessageDialog(null," is" + cRooms.getItemCount());
if (book[t][D]==0)
{
txtDisplay.append("\n" + ">>" + room[t].rName);
txtDisplay.append("\t\t " + " Room is Available");
}
else
{
if (book[t][D]==1)
{
txtDisplay.append("\n" + ">>" + room[t].rName);
txtDisplay.append("\t\t " + " Room Booked");
}
}
}
JOptionPane.showMessageDialog(null, "end " );
}
public void AddDeleteBookRoom()
{
R = (int) cRooms.getSelectedIndex();
D = (int) cDays.getSelectedIndex();
if(book[R][D] == 1)
{
txtDisplay.setText("*****Rooms Detail*****" + "\n" + "Room is Available" + "\n");
book[R][D] = 0;
}
else
{
txtDisplay.setText("*****Rooms Detail*****" + "\n" + "Room Available"+ "\n");
book[R][D] = 0;
}
}
public void AddDeleteRoom()
{
R = (int) cRooms.getSelectedIndex();
D = (int) cDays.getSelectedIndex();
JOptionPane.showMessageDialog(null,"Room selected index " + R);
int intCount =(int) cRooms.getSelectedIndex();
if (intCount != -1)
{
if(book[R][D] == 0 )
{
JOptionPane.showMessageDialog(null,"Room "+room[intCount].rName + " had Deleted");
cRooms.removeItemAt(intCount);
int i;
for( i=intCount;i< cRooms.getItemCount();i++)
JOptionPane.showMessageDialog(null,"Room "+room[i+1].rName + "to");
room=new Rooms(room[i+1]);
JOptionPane.showMessageDialog(null,"Room "+ room.rName );
//cRooms.getSelectedIndex());
// intCount--;
}
else
{
if(book[R][D] == 1 )
{
JOptionPane.showMessageDialog(null,"Room "+room[intCount].rName+" Can Not be Delete");
}
}
}
else
{
JOptionPane.showMessageDialog(null,"Select A Room To be Delete ");
}
}
public void AddNewRoom()
{
JOptionPane.showMessageDialog(null,"Add new room");
}
public void AddClearTextArea()
{
txtDisplay.setText("*****Rooms Detail*****" + "\n");
}
public void AddBookRoom()
{
R= (int) cRooms.getSelectedIndex();
D = (int) cDays.getSelectedIndex();
if(book[R][D] == 0)
{
txtDisplay.setText("*****Rooms Detail*****" + "\n" + "Room is Booked" + "\n");
book[R][D] = 1;
}
else
{
txtDisplay.setText("*****Rooms Detail*****" + "\n" + "Room Not Available"+ "\n");
book[R][D] = 1;
}
}
public void itemStateChanged(ItemEvent itv)
{
if( itv.getSource() == cRooms )
{
R = (int) cRooms.getSelectedIndex();
lblRoomName.setText(room[R].rName);
lblCapacity.setText(room[R].rCapacity);
lblInternet.setText(room[R].rInternet);
lblVideo.setText(room[R].rVideo);
// lblStatus.setText(room[R].rStatus);
}
}
}
<<save as Rooms.java>>
public class Rooms
{
String rName;
String rCapacity;
String rInternet;
String rVideo;
// String rStatus;
Rooms(String a, String b, String c, String d)//, String e)
{
rName = a;
rCapacity = b;
rInternet = c;
rVideo = d;
// rStatus = e;
}
Rooms(Rooms r)
{
rName = r.rName;
rCapacity = r.rCapacity;
rInternet = r.rInternet;
rVideo = r.rVideo;
// rStatus = r.e;
}
}
<<saves as CC.html>>
<html>
<body>
<Applet code = CC.class
width = 600
height = 510>
</Applet>
</body>
</html>

