•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 375,169 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 2,265 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: 2437 | Replies: 4 | Solved
![]() |
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
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
----------------------------------------------
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
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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>
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>
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
<?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> JavaScript != Java.
Please find a JavaScript forum and post your question there.
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
----------------------------------------------
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
- Airline Reservation System (ColdFusion)
- plz help(Airline Reservation System) (C++)
- HELP - Airline Reservation System - ERD required (Computer Science and Software Design)
Other Threads in the JSP Forum
- Previous Thread: Printing the contents of a table
- Next Thread: jsp ui templates



Linear Mode