22
33import myInterface .ClearCheckOut ;
44
5+ import javax .sound .sampled .SourceDataLine ;
56import javax .swing .*;
67import javax .swing .border .EmptyBorder ;
78import javax .swing .table .DefaultTableCellRenderer ;
@@ -47,7 +48,7 @@ public class CheckOut extends JFrame implements ActionListener, myInterface.Clea
4748
4849
4950 public CheckOut () {
50-
51+ System . out . println ( "Currently in CheckOut class" );
5152 setResizable (false );
5253 setTitle ("Admin checkout" );
5354 setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
@@ -255,18 +256,21 @@ public void actionPerformed(ActionEvent e) {
255256 if (yesORno == JOptionPane .YES_OPTION ) {
256257 // Hide current window and show login window
257258 this .setVisible (false );
259+ System .out .println ("Exited from CheckOut class" );
258260 new Login ();
259261 }
260262 } else if (e .getSource () == back_btn ) { // Back button action
261263 // Hide current window and show dashboard window
262264 setVisible (false );
265+ System .out .println ("Exited from CheckOut class" );
263266 new DashBoard ();
264267 } else if (e .getSource () == clear_btn ) { // Clear button action
265268 // Clear checkout fields and adjust table column widths
266269 ClearCheckOut .ClearCheckoutField (CustomerName_fld , CustomerNum_fld , checkInDate_fld , pricePerDay_fld , dayStay_fld , totalAmount_fld , email_fld , search_combo , table );
267270
268271 table .getColumnModel ().getColumn (0 ).setPreferredWidth (80 );
269272 table .getColumnModel ().getColumn (1 ).setPreferredWidth (82 );
273+ System .out .println ("All data cleared from Text Field and Combo Box set to Default" );
270274 }else if (e .getSource () == checkOut_btn ) {
271275 if (search_combo .getSelectedItem () == null ){ //Show error if Search bar is Empty
272276 JOptionPane .showMessageDialog (null , "Error" , "No room is selected" , JOptionPane .WARNING_MESSAGE );
@@ -277,6 +281,7 @@ public void actionPerformed(ActionEvent e) {
277281 String roomNo = (String ) search_combo .getSelectedItem ();
278282 // Create a temporary file to write updated data to
279283 File tempFile = new File ("./files/temp.txt" );
284+ System .out .println ("temp.txt file created" );
280285 PrintWriter pw = new PrintWriter (new FileWriter (tempFile ));
281286 BufferedReader br = new BufferedReader (new FileReader ("./files/rooms.txt" ));
282287 String line2 ;
@@ -288,10 +293,13 @@ public void actionPerformed(ActionEvent e) {
288293 rowData [i ] = br .readLine ();
289294 }
290295 if (rowData [0 ].equals (roomNo )) { // if the room number is a match
296+ System .out .println ("Room number found" );
291297 rowData [4 ] = "Not Booked" ; // update the status
298+ System .out .println ("Updated room details to Not Booked" );
292299 }
293300 // write the updated row data to the temporary file
294301 pw .println ("Rooms Details" );
302+ System .out .println ("Updated details to temp file" );
295303 for (int i = 0 ; i < 5 ; i ++) {
296304 pw .println (rowData [i ]);
297305 }
@@ -305,8 +313,15 @@ public void actionPerformed(ActionEvent e) {
305313 // Replace the original file with the temporary file
306314 File originalFile = new File ("./files/rooms.txt" );
307315 if (originalFile .delete ()) {
308- tempFile .renameTo (originalFile );
309- }
316+ boolean renamed = tempFile .renameTo (originalFile );
317+ if (renamed ) {
318+ System .out .println ("File renamed successfully." );
319+ } else {
320+ System .out .println ("Failed to rename the file." );
321+ }
322+ } else {
323+ System .out .println ("Failed to delete the original file." );
324+ }
310325 } catch (Exception ex ) {
311326 ex .printStackTrace ();
312327 }
@@ -316,7 +331,7 @@ public void actionPerformed(ActionEvent e) {
316331 deleteRoomEntry ();
317332
318333 JOptionPane .showMessageDialog (null , "Check Out Successful" , "Check Out" , JOptionPane .INFORMATION_MESSAGE );
319-
334+ System . out . println ( "CheckOut Done Successfully" );
320335 ClearCheckOut .ClearCheckoutField (CustomerName_fld , CustomerNum_fld , checkInDate_fld , pricePerDay_fld , dayStay_fld , totalAmount_fld , email_fld , search_combo , table );
321336
322337 // Clearing the input fields
@@ -337,6 +352,7 @@ public void actionPerformed(ActionEvent e) {
337352 roomSearch ();
338353 search_combo .setSelectedIndex (-1 );
339354 ClearCheckOut .ClearCheckoutField (CustomerName_fld , CustomerNum_fld , checkInDate_fld , pricePerDay_fld , dayStay_fld , totalAmount_fld , email_fld , search_combo , table );
355+ System .out .println ("All data cleared from Text Field and Combo Box set to Default" );
340356 }
341357 }
342358
@@ -370,11 +386,14 @@ public void actionPerformed(ActionEvent e) {
370386 }
371387 // Check if the room exists
372388 if (DoesRoomExists ) {
389+ System .out .println ("Room Exist" );
373390 // Retrieve customer data
374391 getCustomerData ();
392+ System .out .println ("Customer Data Retrived" );
375393 } else {
376394 // Display an error message if the room is not found
377395 JOptionPane .showMessageDialog (null , "room not found" , "Error" , JOptionPane .WARNING_MESSAGE );
396+ System .out .println ("Room Doesn't not exist" );
378397 search_combo .setSelectedIndex (-1 );
379398
380399 }
@@ -417,9 +436,11 @@ public void actionPerformed(ActionEvent e) {
417436
418437 @ Override
419438 public void deleteRoomEntry () {
439+ System .out .println ("deleteRoomEntry funtion called" );
420440 try {
421441 File inputFile = new File ("./files/checkIn.txt" );
422442 File tempFile = new File ("./files/checkIn_temp.txt" );
443+ System .out .println ("temp file created" );
423444
424445 BufferedReader reader = new BufferedReader (new FileReader (inputFile ));
425446 BufferedWriter writer = new BufferedWriter (new FileWriter (tempFile ));
@@ -446,6 +467,7 @@ public void deleteRoomEntry() {
446467 // write all other lines to the temp file
447468
448469 writer .write (currentLine + System .getProperty ("line.separator" ));
470+ System .out .println ("writting into temp file" );
449471
450472 }
451473 }
@@ -455,17 +477,21 @@ public void deleteRoomEntry() {
455477
456478 // delete the original file
457479 inputFile .delete ();
480+ System .out .println ("Orginal file deleted" );
458481
459482 // rename the temp file to the original file name
460483 tempFile .renameTo (inputFile );
484+ System .out .println ("temp file renamed to orginal file" );
461485
462486 } catch (IOException ex ) {
463487 ex .printStackTrace ();
464488 }
489+ System .out .println ("deleteRoomEntry funtion executed successfully" );
465490 }
466491
467492 @ Override
468493 public void getCustomerData () {
494+ System .out .println ("getCustomerData funtion called" );
469495 DefaultTableModel model ;
470496 model = (DefaultTableModel ) table .getModel ();
471497 model .setRowCount (0 );
@@ -539,9 +565,12 @@ public void getCustomerData() {
539565 CustomerNum_fld .setText (mobileNumber );
540566 pricePerDay_fld .setText (roomPrice );
541567 email_fld .setText (gmail );
568+
569+ System .out .println ("getCustomerData funtion executed successfully" );
542570 }
543571
544572 public void roomSearch () {
573+ System .out .println ("roomSearch funtion called" );
545574 try (BufferedReader br = new BufferedReader (new FileReader ("./files/rooms.txt" ))) {
546575 String line ;
547576 while ((line = br .readLine ()) != null ) {
@@ -559,6 +588,8 @@ public void roomSearch() {
559588 } catch (Exception e ) {
560589 e .printStackTrace ();
561590 }
591+
592+ System .out .println ("roomSearch funtion executed successfully" );
562593 }
563594
564595}
0 commit comments