Jump to content

hi guys here is my GCSE computing coursework i am currently doing task 3. 

 

i have the code(may or may not be written by a friend of mine) but i need to explain it.

 

<head>
<title>Booking system</title>
<p>
<script>
          function readFile()
          {
 
                   var file = [];
 
                   file[0] = "A,0,0,0,0,0,0,0,0,0,0";
                   file[1] = "B,0,0,0,0,0,0,0,0,0,0";
                   file[2] = "C,0,0,0,0,0,0,0,0,0,0";
                   file[3] = "D,0,0,0,0,0,0,0,0,0,0";
                   file[4] = "E,0,0,0,0,0,0,0,0,0,0";
 
                   return file;
          };
 
          function lookForSeats(row, wantedSeats)
          {
                   var done = true;
                   var firstSeat = 0;               
                   var bookedSeats = 0;
                                      
                   
                   
                   for (var x = 1; x < row.length; x++)
                   {
                             
                             if (row[x] == 0)    
                             {
                             
                                      row[x] = 1;
                                      if (firstSeat == 0)
                                      {
                                                
                                                firstSeat = x;     
                                      }
                                      
                                      bookedSeats = bookedSeats + 1;
                                      
                                      if (bookedSeats == wantedSeats)
                                      {
                                                alert("Your seats have been located");
                                                break;
                                      }
                             }
                   }
 
                   
                   if (firstSeat != 0)
                   {        
                             var lastSeat = wantedSeats; 
                             alert("Seats " + row[0] + firstSeat + " - " + row[0] + lastSeat + " are available.");
                   }
                   
 
                   return done;
          };
          
          function processBooking()
          {
                   var success = false; 
 
                   
                   var row = document.getElementById("rowField");
                   var numSeats = document.getElementById("seatsField");
                   
                   
                   var layout = readFile();
 
                   for (var x = 0; x < layout.length; x++)
                   {
                             
                             thisRow = layout[x].split(',');
                   
                             if (row.value == thisRow[0])
                             {
                                      
                                      success = lookForSeats(thisRow, numSeats.value);
                                      break;
                             }
                   }
 
                   if (success == true)
                   {
                             
                   }
                   else
                   {
                             alert("seats not available.");
                   }
          };
 
</script>
</head>
<body>
                   <label>Theatre Booking</label>
                   <br>
 
                   <label>Row</label>
                   <select id="rowField">
                             <option value="A">A</option>
                             <option value="B">B</option>
                             <option value="C">C</option>
                             <option value="D">D</option>
                             <option value="E">E</option>
                   </select>
                   <lable>Number of Seats</label>
                   <select id="seatsField">
                             <option value="1">1</option>
                             <option value="2">2</option>
                             <option value="3">3</option>
                             <option value="4">4</option>
                             <option value="5">5</option>
                             <option value="6">6</option>
                   </select>
 
                   <button type="button" onclick="processBooking()">check availablity</button>
</body>
</html>
 
the following is the specific piece i need help with 
 
              for (var x = 1; x < row.length; x++)
                   {
                             
                             if (row[x] == 0)    
                             {
                             
                                      row[x] = 1;
                                      if (firstSeat == 0)
                                      {
                                                
                                                firstSeat = x;     
                                      }
                                      
                                      bookedSeats = bookedSeats + 1;
                                      
                                      if (bookedSeats == wantedSeats)
                                      {
                                                alert("Your seats have been located");
                                                break;
                                      }
                             }
                   }
 
                   
                   if (firstSeat != 0)
                   {        
                             var lastSeat = wantedSeats; 
                             alert("Seats " + row[0] + firstSeat + " - " + row[0] + lastSeat + " are available.");
                   }
                   
 
                   return done;
          };
          
          function processBooking()
          {
                   var success = false; 
 
                   
                   var row = document.getElementById("rowField");
                   var numSeats = document.getElementById("seatsField");
                   
                   
                   var layout = readFile();
 
                   for (var x = 0; x < layout.length; x++)
                   {
                             
                             thisRow = layout[x].split(',');
                   
                             if (row.value == thisRow[0])
                             {
                                      
                                      success = lookForSeats(thisRow, numSeats.value);
                                      break;
                             }
                   }
 
                   if (success == true)
                   {
                             
                   }
                   else
                   {
                             alert("seats not available.");
 
pls help thanks in advance for any responses
 

A453CA4Jun16_85871-Emmail_booking.pdf

Link to comment
https://linustechtips.com/topic/308567-gcse-computing-javahtml/
Share on other sites

Link to post
Share on other sites

Is there any spesific part of the code that you don't understand? It'd be really helpful if you were to highlight the parts of the code that you have problems with. Also, as others have pointed out, it is important to know the difference between Java and JavaScript. JavaScript is used to make website scripts whereas Java creates standalone programs.

Link to comment
https://linustechtips.com/topic/308567-gcse-computing-javahtml/#findComment-4204501
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×