i have to create a n hotel management program using GUI, i hava done the gui part so far but i need help in creating the actionPerformed class,how am i supposed to do the reservation,and select rooms for 2 persons or one and rooms that overlook the sea or the road,this kind of stuff,please help me ,i heve to do it in 2 days.thanks

Recommended Answers

All 3 Replies

how am i supposed to do the reservation,and select rooms for 2 persons or one and rooms that overlook the sea or the road

Could you please post your whole assignment, including the GUI-code you have written so far?

Forget the GUI for the moment. Go back to where you should have started, which is the hotel model. You need to design some simple classes for entities such as Room ( attributes: no of beds, sea view etc), Hotel (a collection of Rooms with methods for finding vacant Rooms with specific attributes), and Reservation (person, Room, dates etc).
Define these classes with simple constructors, and public methods for the things you want to do (eg find a twin room with sea view, create a new Reservation for that Room).
Write some simple hard-coded tests in a main(..) method to make sure they work.
Now go back to the GUI - your ActionPerformed will just be just like the tests you coded but with data from the GUI fields.

i have done only one option,if the rooms are for 2 or for 1 person.i type in the name ,the option and the result in the text area appears even before i press save and its always room number 10 ,i would also like to add it another option for ex viewing the sea or the road and how can i make it to appear a second panel demostrating the name room and that the reservation was really successful.i am sorry for so much questions but i am a beginner.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class HotelManagement extends JFrame implements ActionListener
{ JLabel tekst1=new JLabel("Name ");
  JTextArea intekst1= new JTextArea(1,7);
  JLabel tekst2=new JLabel("Surname ");
  JTextArea intekst2= new JTextArea(1,7);
  JPanel tekst1Panel= new JPanel();
  JPanel tekst2Panel= new JPanel();
  JTextArea ana= new JTextArea(2,25);
  JRadioButton couple=new JRadioButton("Couple room");
  JRadioButton one=new JRadioButton("One person");
   ButtonGroup choiceGroup= new ButtonGroup();
  JButton save= new JButton("Save");
  
  public HotelManagement()
  {super ("Hotel Management");
   setSize(350,250);
   setVisible(true);
   
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   
   choiceGroup.add(dhomaCift);
   choiceGroup.add(dhomaTek);
   
   JPanel choicePanel= new JPanel();
   choicePanel.setLayout(new BoxLayout(choicePanel,BoxLayout.Y_AXIS));
   choicePanel.add(dhomaCift);
   choicePanel.add(dhomaTek);
   
   Container content= getContentPane();
   FlowLayout lay=new FlowLayout(FlowLayout.LEFT);
   content.setLayout(lay);
   setBackground(Color.blue);
   
   
   couple.addActionListener(this);
   one.addActionListener(this);
   save.addActionListener(this);
   
   
   tekst1Panel.add(tekst1);
   tekst1Panel.add(intekst1);
   tekst2Panel.add(tekst2);
   tekst2Panel.add(intekst2);
   
   content.setLayout(lay);
   content.add(tekst1Panel);
   content.add(tekst2Panel);
   content.add(zgjedhjePanel);
   content.add(ana);
   content.add(rezervo);
   
   setContentPane(content);
    }
  public void savecoupleroom()
  {String[] coupleroom={"1","2","3","4","5","6","7","8","9","10"};
        for(int i=0 ;i<=coupleroom.length;i++)
        {if (i>coupleroom.length)
             {String str="No more couple rooms";
              ana.setText(str);}
        else{ coupleroom[i]=coupleroom[i+1];
             String str1="Couple room"+coupleroom[i]+"saved";
              ana.setText(str1);}
        }
  }
  public void saveoneroom()
  {String[] oneroom={"1","2","3","4","5","6","7","8","9","10"};
        for(int i=0 ;i<=oneroom.length;i++)
        {if (i>oneroom.length)
             {String str="No more rooms for one person";
             ana.setText(str);}
        else{ oneroom[i]=oneroom[i+1];
        String str1="One person room"+oneroom[i]+"saved";

        ana.setText(str1);}
        }
  }
  public void actionPerformed(ActionEvent event)
  {  if(event.getSource()==couple)
         {savecoupleroom();}
	  if (event.getSource()==one)
	  {saveoneroom();}
	  
	  
  }
  
  
  
  
  
  public static void main(String[] args)
  {HotelManagement manage= new HotelManagement();}
  
  
  

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.