Sei sulla pagina 1di 11

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package flight.

reservation; import javax.swing.*; /** * * @author jrm */ public class AirlineReservation extends javax.swing.JFrame { double Economy = 0.00; double BusinessClass = 0.00; double FirstClass = 0.00; double StandardFare = 0.00; String fligthType = " "; Double AdultFare = 0.00; Double ChildFare = 0.00; Double InfantFare = 0.00; /** * Creates new form AirlineReservation */ public AirlineReservation() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { grpFligth = new javax.swing.ButtonGroup(); grpFligthType = new javax.swing.ButtonGroup(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); txtName = new javax.swing.JTextField(); txtAddress = new javax.swing.JTextField(); txtContactNumber = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); radRoundTrip = new javax.swing.JRadioButton(); radOneWay = new javax.swing.JRadioButton(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); cboOrigin = new javax.swing.JComboBox(); cboDestination = new javax.swing.JComboBox(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); radEconomy = new javax.swing.JRadioButton(); radBusinessClass = new javax.swing.JRadioButton(); radFirstClass = new javax.swing.JRadioButton(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel();

spnAdult = new javax.swing.JSpinner(); spnChild = new javax.swing.JSpinner(); spnInfant = new javax.swing.JSpinner(); btnProcessReservation = new javax.swing.JButton(); ftxtDepartureDate = new javax.swing.JFormattedTextField(); ftxtReturnDate = new javax.swing.JFormattedTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Pink Airline Fligth Reservation System"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); jLabel1.setText("Name:"); jLabel2.setText("Address:"); jLabel3.setText("Contact Number:"); jLabel4.setText("Fligth:"); grpFligth.add(radRoundTrip); radRoundTrip.setText("Round Trip"); radRoundTrip.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { radRoundTripActionPerformed(evt); } }); grpFligth.add(radOneWay); radOneWay.setText("One Way"); radOneWay.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { radOneWayActionPerformed(evt); } }); jLabel5.setText("Origin:"); jLabel6.setText("Destination:"); cboOrigin.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " Manila", "Tokyo", "Paris", "New York" })); cboOrigin.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cboOriginActionPerformed(evt); } }); cboDestination.setModel(new javax.swing.DefaultComboBoxModel(new String[ ] { "Manila", "Tokyo", "Paris", "New York" })); jLabel7.setText("Departure Date:"); jLabel8.setText("Return Date:"); jLabel9.setText("Fligth Type:");

grpFligthType.add(radEconomy); radEconomy.setText("Economy"); radEconomy.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { radEconomyActionPerformed(evt); } }); grpFligthType.add(radBusinessClass); radBusinessClass.setText("Business Class"); radBusinessClass.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { radBusinessClassActionPerformed(evt); } }); grpFligthType.add(radFirstClass); radFirstClass.setText("First Class"); radFirstClass.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { radFirstClassActionPerformed(evt); } }); jLabel10.setText("Adult(12+ years):"); jLabel11.setText("Child(2-11 years):"); jLabel12.setText("Infant(<2 years):"); btnProcessReservation.setText("Process Reservation"); btnProcessReservation.addActionListener(new java.awt.event.ActionListene r() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnProcessReservationActionPerformed(evt); } }); ftxtDepartureDate.setFormatterFactory(new javax.swing.text.DefaultFormat terFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstan ce(java.text.DateFormat.SHORT)))); ftxtReturnDate.setFormatterFactory(new javax.swing.text.DefaultFormatter Factory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance( java.text.DateFormat.SHORT)))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP ane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING ) .addGroup(layout.createSequentialGroup() .addGap(40, 40, 40) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addComponent(jLabel4) .addComponent(jLabel5) .addComponent(jLabel6) .addComponent(jLabel7)

.addComponent(jLabel8) .addComponent(jLabel9)) .addGap(33, 33, 33) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLa yout.Alignment.LEADING) .addComponent(radEconomy) .addComponent(radBusinessClass) .addComponent(radFirstClass)) .addGap(49, 49, 49) .addGroup(layout.createParallelGroup(javax.swing.GroupLa yout.Alignment.LEADING) .addComponent(btnProcessReservation, javax.swing.Gro upLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing .GroupLayout.Alignment.LEADING) .addComponent(jLabel10) .addComponent(jLabel11) .addComponent(jLabel12)) .addGap(29, 29, 29) .addGroup(layout.createParallelGroup(javax.swing .GroupLayout.Alignment.LEADING) .addComponent(spnAdult, javax.swing.GroupLay out.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayou t.PREFERRED_SIZE) .addComponent(spnInfant, javax.swing.GroupLa yout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayo ut.PREFERRED_SIZE) .addComponent(spnChild, javax.swing.GroupLay out.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayou t.PREFERRED_SIZE))))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout .Alignment.TRAILING, false) .addComponent(ftxtReturnDate, javax.swing.GroupLayout.Al ignment.LEADING) .addComponent(ftxtDepartureDate, javax.swing.GroupLayout .Alignment.LEADING) .addComponent(cboDestination, javax.swing.GroupLayout.Al ignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cboOrigin, 0, javax.swing.GroupLayout.DEFA ULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(radRoundTrip) .addGap(102, 102, 102)))) .addContainerGap(29, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGap(103, 103, 103) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel1)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(65, 65, 65) .addComponent(radOneWay))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.RELATED, 27, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLa yout.Alignment.TRAILING) .addComponent(txtAddress, javax.swing.GroupLayout.PR EFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING) .addComponent(txtContactNumber, javax.swing.Grou pLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtName, javax.swing.GroupLayout.P REFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(60, 60, 60)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING ) .addGroup(layout.createSequentialGroup() .addGap(26, 26, 26) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel1) .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZ E, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE LATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel2) .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_ SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SI ZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE LATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel3) .addComponent(txtContactNumber, javax.swing.GroupLayout.PREF ERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFER RED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(radRoundTrip) .addComponent(jLabel4) .addComponent(radOneWay)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE LATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel5) .addComponent(cboOrigin, javax.swing.GroupLayout.PREFERRED_S IZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZ E)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE)

.addComponent(cboDestination, javax.swing.GroupLayout.PREFER RED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRE D_SIZE) .addComponent(jLabel6)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel7) .addComponent(ftxtDepartureDate, javax.swing.GroupLayout.PRE FERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFE RRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel8) .addComponent(ftxtReturnDate, javax.swing.GroupLayout.PREFER RED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRE D_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLa yout.Alignment.LEADING) .addComponent(jLabel9) .addGroup(layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.BASELINE) .addComponent(radEconomy) .addComponent(jLabel10))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLa yout.Alignment.BASELINE) .addComponent(radBusinessClass) .addComponent(jLabel11)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLa yout.Alignment.BASELINE) .addComponent(radFirstClass) .addComponent(jLabel12))) .addGroup(layout.createSequentialGroup() .addComponent(spnAdult, javax.swing.GroupLayout.PREFERRE D_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_ SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addComponent(spnChild, javax.swing.GroupLayout.PREFERRE D_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_ SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addComponent(spnInfant, javax.swing.GroupLayout.PREFERR ED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED _SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addComponent(btnProcessReservation, javax.swing.GroupLayout.DEF AULT_SIZE, 37, Short.MAX_VALUE) .addContainerGap())

); pack(); }// </editor-fold> private void btnProcessReservationActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:] if(txtName.getText().length() < 0 || txtAddress.getText().length() <0 || txtContactNumber.getText().length() < 0 || grpFligth.isSelected (null) || grpFligthType.isSelected(null)){ JOptionPane.showMessageDialog(null, "Incomplete Data!!"); }else if(cboOrigin.getSelectedItem() == cboDestination.getSelectedItem()){ JOptionPane.showMessageDialog(null, "Departure must be different with Ori gin!!"); }else{ if(cboOrigin.getSelectedItem() == "Manila" && cboDestination.getSelect edItem() == "Tokyo" || cboOrigin.getSelectedItem() == "Tokyo" && cboDestination.getSe lectedItem() == "Manila"){ Economy = 400; BusinessClass =700; FirstClass = 1000; }else if(cboOrigin.getSelectedItem() == "Manila" && cboDestination.get SelectedItem() == "Paris" || cboOrigin.getSelectedItem() == "Paris" && cboOrigin.getSelecte dItem() == "Manila"){ Economy = 900; BusinessClass =1200; FirstClass = 1500; }else if(cboOrigin.getSelectedItem() == "Manila" && cboDestination.get SelectedItem() == "New York" || cboOrigin.getSelectedItem() == "New York" && cboDestination.ge tSelectedItem() == "Manila"){ Economy = 700; BusinessClass =1000; FirstClass = 1300; }else if(cboOrigin.getSelectedItem() == "Tokyo" && cboDestination.getS electedItem() == "Paris" || cboOrigin.getSelectedItem() == "Paris" && cboDestination.getSe lectedItem() == "Tokyo"){ Economy = 800; BusinessClass = 1100; FirstClass = 1400; }else if(cboOrigin.getSelectedItem()== "Tokyo" && cboDestination.getS electedItem() == "New York" || cboOrigin.getSelectedItem()== "New York" && cboDestination.ge tSelectedItem() == "Tokyo"){ Economy = 600; BusinessClass =900; FirstClass = 1200; }else if(cboOrigin.getSelectedItem() == "Paris" && cboDestination.get SelectedItem()== "New York" || cboOrigin.getSelectedItem() == "New York" && cboDestination.g etSelectedItem() == "Paris"){ Economy = 500;

BusinessClass =800; FirstClass = 1100; } if(radOneWay.isSelected() == true){ if(radEconomy.isSelected() == true){ StandardFare = Economy; }else if(radBusinessClass.isSelected() == true){ StandardFare = BusinessClass; }else if(radFirstClass.isSelected() == true){ StandardFare = FirstClass; } }else if(radRoundTrip.isSelected() == true){ if(radEconomy.isSelected() == true){ StandardFare = Economy * 2; }else if(radBusinessClass.isSelected() == true){ StandardFare = BusinessClass *2; }else if(radFirstClass.isSelected() == true){ StandardFare = FirstClass *2; } } AdultFare = StandardFare * Double.parseDouble(spnAdult.getValue().toSt ring()); if (spnChild.getValue() == 0){ ChildFare = StandardFare * 0; }else{ ChildFare = StandardFare - (StandardFare* 0.2) * Double.parseDoubl e(spnChild.getValue().toString()); } if (spnInfant.getValue() == 0){ InfantFare = StandardFare * 0; }else{ InfantFare = StandardFare - (StandardFare * 0.5) * Double.parseDou ble(spnInfant.getValue().toString()); } Double TotalFare = AdultFare + ChildFare + InfantFare; JOptionPane.showMessageDialog(null, "Fligth Reservation Details: " + " \n" + "Name: " + txtName.getText() + "\n" + "Address: " + txtAddress.getText() + "\n" + "Contact Number: " + txtContactNumber.getText() + "\n" + "Origin: "+ cboOrigin.getSelectedItem() + "\n" + "Destination: " + cboDestination.getSelectedItem() + "\n" + "Stnadard Air Fare(" + fligthType +"):" + StandardFare +"\n" + "Adult Fare (x"+ spnAdult.getValue().toString() +"):" + AdultF are + "\n" + "Child Fare (x"+ spnChild.getValue().toString() + "):" + Child Fare + "\n" + "Infant Fare (x" + spnInfant.getValue().toString() + "):" + In fantFare + "\n" + "Total Air Fare: " + TotalFare + "\n" + "Departure Date: " + ftxtDepartureDate.getText() + "\n" + "Return Date: " + ftxtReturnDate.getText(),"Message", WIDTH); } } private void radOneWayActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here: if (radOneWay.isSelected() == true){ ftxtReturnDate.disable(); fligthType = "One Way"; ftxtReturnDate.setText(null); } } private void radRoundTripActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (radRoundTrip.isSelected() == true){ ftxtReturnDate.enable(); fligthType = "RoundTrip"; } } private void radEconomyActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void radBusinessClassActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void radFirstClassActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void cboOriginActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void formWindowOpened(java.awt.event.WindowEvent evt) { // TODO add your handling code here: } /** * @param args the command line arguments */ public static void main(String args[]) { /* * Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod e (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see

* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.h tml */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana ger.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(AirlineReservation.class.getName( )).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(AirlineReservation.class.getName( )).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(AirlineReservation.class.getName( )).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(AirlineReservation.class.getName( )).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new AirlineReservation().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnProcessReservation; private javax.swing.JComboBox cboDestination; private javax.swing.JComboBox cboOrigin; private javax.swing.JFormattedTextField ftxtDepartureDate; private javax.swing.JFormattedTextField ftxtReturnDate; private javax.swing.ButtonGroup grpFligth; private javax.swing.ButtonGroup grpFligthType; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JRadioButton radBusinessClass; private javax.swing.JRadioButton radEconomy; private javax.swing.JRadioButton radFirstClass; private javax.swing.JRadioButton radOneWay;

private javax.swing.JRadioButton radRoundTrip; private javax.swing.JSpinner spnAdult; private javax.swing.JSpinner spnChild; private javax.swing.JSpinner spnInfant; private javax.swing.JTextField txtAddress; private javax.swing.JTextField txtContactNumber; private javax.swing.JTextField txtName; // End of variables declaration }

Potrebbero piacerti anche