User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 391,138 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,170 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 2569 | Replies: 4 | Solved
Reply
Join Date: Apr 2007
Posts: 3
Reputation: imastudent is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
imastudent imastudent is offline Offline
Newbie Poster

Airline Reservation System..

  #1  
Apr 17th, 2007
Hello guys! im a newbie in programming and i need help..Anyone familiar with array??below is the case and i hope someone can help me.. thx..

Write a program to assign seats on each flight of the airline’s only plane (capacity: 20 seats). Your program should display the following menu of alternatives: Please type 1 for "Business" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first-class section (seats 1–10). If the person types 2, your program should assign a seat in the economy section (seats 11–20). Your program should print a boarding pass indicating the person’s seat number and whether it is in the first-class or economy section of the plane.

Use a one-dimensional array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.

Your program should never assign a seat that has already been assigned.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,360
Reputation: masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough 
Rep Power: 8
Solved Threads: 117
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: Airline Reservation System..

  #2  
Apr 17th, 2007
Well, start coding. If you have a problem post again, with your code and a description of your problem, along with any error messages (complete) and we will help, but we are not going to write it for you.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Apr 2007
Posts: 3
Reputation: imastudent is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
imastudent imastudent is offline Offline
Newbie Poster

Re: Airline Reservation System..

  #3  
Apr 23rd, 2007
Hi again..this is what i do so far..
but there is still a problem, bcos my teacher told me that the seats must be randomly assigned..So for example, user choose Business, then the seats go random between 1 to 5..

<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Solution11.16 -->
<!-- Airline Reservation System-->

<html xmlns = "http://www.w3.org/1999/xhtml">

<head>
<title>Airline Reservation System</title>

<script type = "text/javascript">
<!--

var input;
var secondInput;
var element;
var secondElement;
var firstCount = 0;
var economyCount = 0;
var seats = [ ,0,0,0,0,0,0,0,0,0,0]; //allocate 10-element Array

function startArray()
{


for(var i=0; i<11; i++)
{

input = window.prompt("Please type 1 for First Class and Please type 2 for Economy.","0");

if (input == 1 || input == 2)
{
element = linearSearch(seats);
if (element==-1 && input == 1)
{
document.writeln("The First Class is already fully booked<br/>");
secondQuestion(seats);
}
else if (element ==-1 && input == 2)
{
document.writeln("The Economy Class is already fully booked<br/>");
secondQuestion(seats);
}
else
boardingPass(input);
}


//to terminate the program
else
{
window.status = "Bye-bye!";
System.exit(0);
}


}
}

function linearSearch(theArray)
{
if (input == 1)
{
for (var n=0; n<6 ; n++)
if (theArray [n] == 0)
return n;
}
else if (input == 2)
{
for (var n=6; n<11 ; n++)
if (theArray [n] == 0)
return n;
}
return -1;
}

function boardingPass(theInput)
{
if (input ==1)
{
document.writeln("----------BOARDING PASS----------<br/>");
document.writeln("You are allocated in the First Class<br/>");
document.writeln("Your seat number is "+ element+"<br/>");
document.writeln("-----------------------------------------<br/>");
seats[element]= 1;
firstCount++;
}
else if (input ==2)
{
document.writeln("----------BOARDING PASS----------<br/>");
document.writeln("You are allocated in the Economy Class<br/>");
document.writeln("Your seat number is "+ element +"<br/>");
document.writeln("-----------------------------------------<br/>");
seats[element]= 1;
economyCount++;
}

}

function secondQuestion(theArray)
{
if (input == 1)
{
for (var n=6; n<11 ;n++)
{
if (theArray [n] == 0)
{
secondInput = window.prompt("Do you want to move to Economy Class? (If YES, please press 1. If NO, please press 2)","0");
if ( secondInput == 1)
{

input = 2;
element=linearSearch(seats);
document.writeln("You have been allocated to Economy Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.writeln("Next flight leaves in 3 hours<br/>");
break;
}
}
}
}
else if (input == 2)
{
for (var n=0; n<6 ;n++)
{
if (theArray [n] == 0)
{
secondInput = window.prompt("Do you want to move to First Class? (If YES, please press 1. If NO, please press 2)","0");
if ( secondInput == 1)
{
input = 1;
element=linearSearch(seats);
document.writeln("You have been allocated to First Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.writeln("Next flight leaves in 3 hours<br/>");
break;
}
}
}
}

}


//-->
</script>

</head>
<body onload = "startArray()"></body>
</html>
Reply With Quote  
Join Date: Apr 2007
Posts: 3
Reputation: imastudent is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
imastudent imastudent is offline Offline
Newbie Poster

Re: Airline Reservation System..

  #4  
Apr 23rd, 2007
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Solution11.16 -->
<!-- Airline Reservation System-->

<html xmlns = "http://www.w3.org/1999/xhtml">

    <head>
        <title>Airline Reservation System</title>

        <script type = "text/javascript">
        <!--
        
        var input;
        var secondInput;
        var element;
        var secondElement;
        var firstCount = 0;
        var economyCount = 0;
        var seats = [ ,0,0,0,0,0,0,0,0,0,0];            //allocate 10-element Array
        
        function startArray()
        {
            

            for(var i=0; i<11; i++)
            {
                
                    input = window.prompt("Please type 1 for First Class and Please type 2 for Economy.","0");

                    if (input == 1 || input == 2)
                    {
                        element = linearSearch(seats);
                        if (element==-1 && input == 1)
                        {
                            document.writeln("The First Class is already fully booked<br/>");
                            secondQuestion(seats);
                        }
                        else if (element ==-1 && input == 2)
                        {
                            document.writeln("The Economy Class is already fully booked<br/>");
                            secondQuestion(seats);
                        }
                        else
                            boardingPass(input);    
                    }
                    
                    
                    //to terminate the program
                    else 
                    {
                        window.status = "Bye-bye!";
                        System.exit(0);
                    }
                    
                    
            }
        }
        
        function linearSearch(theArray)
        {
            if (input == 1)
            {
                for (var n=0; n<6 ; n++)
                    if (theArray [n] == 0)
                        return n;
            }
            else if (input == 2)
            {
                for (var n=6; n<11 ; n++)
                    if (theArray [n] == 0)
                        return n;
            }
            return -1;
        }

        function boardingPass(theInput)
        {
            if (input ==1)
            {    
                document.writeln("----------BOARDING PASS----------<br/>");
                document.writeln("You are allocated in the First Class<br/>");
                document.writeln("Your seat number is "+ element+"<br/>");
                 document.writeln("-----------------------------------------<br/>");
                seats[element]= 1;
                firstCount++;    
            }
            else if (input ==2)
            {    
                document.writeln("----------BOARDING PASS----------<br/>");
                document.writeln("You are allocated in the Economy Class<br/>");
                document.writeln("Your seat number is "+ element +"<br/>");
                document.writeln("-----------------------------------------<br/>");
                seats[element]= 1;
                economyCount++;    
            }
            
        }

        function secondQuestion(theArray)
        {
            if (input == 1)
            {
                for (var n=6; n<11 ;n++)
                {
                    if (theArray [n] == 0)
                    {
                        secondInput = window.prompt("Do you want to move to Economy Class? (If YES, please press 1. If NO, please press 2)","0");
                            if ( secondInput == 1)
                            {
                                
                                input = 2;
                                element=linearSearch(seats);
                                document.writeln("You have been allocated to Economy Class<br/>");
                                boardingPass(input);
                                break;
                            }
                            else if (secondInput == 2)
                            {
                                document.writeln("Next flight leaves in 3 hours<br/>");
                                break;
                            }
                    }
                }
            }
            else if (input == 2)
            {
                for (var n=0; n<6 ;n++)
                {
                    if (theArray [n] == 0)
                    {
                        secondInput = window.prompt("Do you want to move to First Class? (If YES, please press 1. If NO, please press 2)","0");
                            if ( secondInput == 1)
                            {
                                input = 1;
                                element=linearSearch(seats);
                                document.writeln("You have been allocated to First Class<br/>");
                                boardingPass(input);
                                break;
                            }
                            else if (secondInput == 2)
                            {
                                document.writeln("Next flight leaves in 3 hours<br/>");
                                break;
                            }
                    }
                }
            }
            
        }


        //-->
        </script>

    </head>
    <body onload = "startArray()"></body>
</html>
Reply With Quote  
Join Date: Feb 2006
Posts: 1,360
Reputation: masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough 
Rep Power: 8
Solved Threads: 117
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: Airline Reservation System..

  #5  
Apr 23rd, 2007
JavaScript != Java.

Please find a JavaScript forum and post your question there.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 6:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC