473,782 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

booking system

Hi all,

i am new to javascript and was wondering if anyone can help with this
assignment?

Any help will be great.

Shannon

A small airline has just purchased a computer for its new automated
reservation system. You have been asked to program the new system. You
are to write a JavaScript program to assign seats on the next flight of
the airline's only plane (capacity 10 seats). Your program should
display a web page that asks for the passenger name and provides the
following alternatives: Please type 1 for "First Class" and Please
type 2 for "Economy". If the person types 1, your program should
assign a seat in the first class section (seats 1-5). If the person
types 2, your program should assign a seat in economy section (seats
6-10). Your program should output boarding pass information indicating
the passenger name, seat number, and whether it is in the first class
or economy section of the plane.
Your program should, of course, never assign a seat that has already
been assigned. When the first class section is full, your program
should ask the person if it is acceptable to be placed in the economy
section (and vice versa). If yes, then make the appropriate seat
assignment. If no, then output the message: " Next flight leaves in 3
hours."
Your program should be able to output a list of passengers who have
reservations.
Hint: Use an array to represent the seating chart of the plane. As each
seat is assigned, store the passenger name in the corresponding array
element to indicate that the seat is no longer available.

Nov 23 '05 #1
8 4222
In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
sh***********@h otmail.co.uk says...
Hi all,

i am new to javascript and was wondering if anyone can help with this
assignment?

Any help will be great.


What has your tutor said? As this requires more than basic JS
knowledge, I suspect you've missed something at school.

--

Hywel
http://kibo.org.uk/
Nov 23 '05 #2
shannon wrote:
i am new to javascript and was wondering if anyone can help with this
assignment?
[...]
[homework]


Sorry, the whole idea of homework is that _you_ do it to teach yourself
(work at home), not be teached by others. I think if you posted code
snippets of your non-working approach to solve the problem, all here will
gladly clarify any misconceptions that caused it. But first it is up to
_you_ to develop that approach in order to show that you have understood
the basics you should have learned in class. Think about it: Would you
like to work with people who do not know what they do? Would you employ
such a person?

<http://jibbering.com/faq/>
PointedEars
Nov 23 '05 #3
I have been attending classes and trying to figure this out. Can you
help me with this piece, i think the if statement is not executing
properly.

<html>
<HEAD>
<TITLE>Performi ng Comparisons</TITLE>

<SCRIPT LANGUAGE = "JavaScript ">

var passengerName; // first string entered by user
var seatType; // second string entered by user
var classType;
// read first number from user as a string and assigns to var first
passengerName = window.prompt( "Enter your name:", "0" );

// read second number from user as a string and assigns to var
second
seatType = window.prompt( "For First Class type 1 or 2 for
Economy:", "0" );

if (seatType ==1){
classType = ("First Class");
Else
classType=("Eco nomy")};

document.writel n( "<H1>Boardi ng Pass Information</H1>" );
document.writel n( "<TABLE BORDER = \"1\"" + "WIDTH = \"40%\">");
document.writel n( "<TR><TD>" + "<b>" +"NAME:" + "</b>" +
"</TD></TR>" );
document.writel n( "<TR><TD>" + passengerName +
"</TD></TR>" );
document.writel n( "<TR><TD>" + "<b>" + "SEAT TYPE"+ "</b>" +
"</TD></TR>" );
document.writel n( "<TR><TD>" + seatType+
"</TD></TR>" );
document.writel n( "<TR><TD>" + "<b>" + "CLASS TYPE"+ "</b>" +
"</TD></TR>" );
document.writel n( "<TR><TD>" + classType +
"</TD></TR>" );
document.writel n( "</TABLE>" );
</SCRIPT>

</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run the script again</P>
</BODY>
</HTML>

Nov 23 '05 #4
shannon said the following on 11/18/2005 4:52 PM:
I have been attending classes and trying to figure this out. Can you
help me with this piece, i think the if statement is not executing
properly.
<snip>

if (seatType ==1){
classType = ("First Class");
Else


else != Else

You should get a syntax error on the above line.

You also have bracket mismatch.

if (condition){
//true branch
}
else{
//false branch
}
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #5
shannon wrote:
<SCRIPT LANGUAGE = "JavaScript ">
If you have learned that in class, it is wrong. The `language' attribute is
deprecated, the `type' attribute is required for HTML4's `script' element.
Use

<script type="text/javascript">

Use <URL:http://validator.w3.or g/> to identify other invalid markup
which could (and will) affect the proper execution of your script code
that is operating on it.
var passengerName; // first string entered by user
var seatType; // second string entered by user
var classType;
// read first number from user as a string and assigns to var first
passengerName = window.prompt( "Enter your name:", "0" );

// read second number from user as a string and assigns to var
second
seatType = window.prompt( "For First Class type 1 or 2 for
Economy:", "0" );

if (seatType ==1){ ^
window.prompt() returns either a string or `null'. You are relying
on automatic type conversion of the number 1 to string due to its
comparison with a string. Not a Bad Thing, but something to watch for.
classType = ("First Class");
So you open the block above with `{' but do not close it with `}'.
v Else ^^^^
As JS/ECMAScript is case-sensitive, there is no `Else' statement
but an `else' statement. Probably but a typo you overlooked :)
classType=("Eco nomy")}; ^
There. You are closing the block too late. It should be

if (...)
{
// ...
}
else
{
// ...
}

Consequent proper indentation helps :)
document.writel n( "<H1>Boardi ng Pass Information</H1>" );
document.writel n( "<TABLE BORDER = \"1\"" + "WIDTH = \"40%\">");
Those two lines should be written as

document.write([
'<h1>Boarding Pass Information<\/h1>',
'<table border="1" width="40%">'
].join("\n"));

Consecutive calls of document.write( ) are always inefficient and
often error-prone. Especially it is error-prone to
document.writel n( "<TR><TD>" + "<b>" +"NAME:" + "</b>" +
"</TD></TR>" );


write elements separately that only make sense to the markup parser in
combination, such as table-related elements (table, thead, tbody, tfoot,
tr, th, td).
HTH

PointedEars

P.S.
Please provide attribution and trimmed quotes next time:
<URL:http://jibbering.com/faq/faq_notes/pots1.html>
Nov 23 '05 #6

shannon wrote:
I have been attending classes and trying to figure this out. Can you
help me with this piece, i think the if statement is not executing
properly.

<html>
<HEAD>
<TITLE>Performi ng Comparisons</TITLE>

<SCRIPT LANGUAGE = "JavaScript "> The language attribute is deprecated, use the type attribute instead:

<script type = "text/javascript">

var passengerName; // first string entered by user
var seatType; // second string entered by user
var classType;
// read first number from user as a string and assigns to var first
passengerName = window.prompt( "Enter your name:", "0" );

// read second number from user as a string and assigns to var
second
seatType = window.prompt( "For First Class type 1 or 2 for
Economy:", "0" );
In regards to this assignment, it seems that you should be placing
those in a form instead of doing a prompt. For example, what would
happen if a user wanted to get 2 or more seats? If I refresh the page,
all data is lost, unless you've learned how to use cookies.

if (seatType ==1){
classType = ("First Class"); }

Place matching closing brace here.
Else
Syntax is case sensitive. That should be a lowercase 'e' instead.
classType=("Eco nomy")};

document.writel n( "<H1>Boardi ng Pass Information</H1>" );
document.writel n( "<TABLE BORDER = \"1\"" + "WIDTH = \"40%\">");
document.writel n( "<TR><TD>" + "<b>" +"NAME:" + "</b>" +
"</TD></TR>" );
document.writel n( "<TR><TD>" + passengerName +
"</TD></TR>" );
document.writel n( "<TR><TD>" + "<b>" + "SEAT TYPE"+ "</b>" +
"</TD></TR>" );
document.writel n( "<TR><TD>" + seatType+
"</TD></TR>" );
document.writel n( "<TR><TD>" + "<b>" + "CLASS TYPE"+ "</b>" +
"</TD></TR>" );
document.writel n( "<TR><TD>" + classType +
"</TD></TR>" );
document.writel n( "</TABLE>" );
Instead of doing bunch of document.writel n, it would be easier to
create a form and then manipulate the values of the input therein.
</SCRIPT>

</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run the script again</P>
</BODY>
</HTML>


Nov 23 '05 #7
shannon wrote:
[...]
Another remark:
if (seatType ==1){
classType = ("First Class");
Else
classType=("Eco nomy")};


You need not enclose any literals (here: string literals) in parentheses.
It will only confuse you when you call your own functions/methods later.

if (seatType == 1)
{
classType = "First Class";
}
else
{
classType = "Economy";
}

And for another thing to think about, find out what the following does:

classType = (seatType == 1) ? "First Class" : "Economy";
Happy coding :)

PointedEars
Nov 23 '05 #8
JRS: In article <14************ ****@PointedEar s.de>, dated Sat, 19 Nov
2005 00:01:57, seen in news:comp.lang. javascript, Thomas 'PointedEars'
Lahn <Po*********@we b.de> posted :
shannon wrote: if (seatType == 1)
{
classType = "First Class";
}
else
{
classType = "Economy";
}

And for another thing to think about, find out what the following does:

classType = (seatType == 1) ? "First Class" : "Economy";


Neither of those matches the originally stated requirement.

--
© John Stockton, Surrey, UK. ??*@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.
Nov 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
18692
by: Dave Robinson | last post by:
I was wondering if anyone could help me with a problem I'm having. I've been using Dreamweaver to create a hotel booking system for a friend of mine, using MySQL (version 4.0.21) and PHP 5. The bit I'm struggling with is checking the Room Availability based on dates that are typed into a textfield and then returning a list of the available rooms on the next page. The three tables involved in this function are: CREATE TABLE `room` (
2
16816
by: PaulD | last post by:
Can anyone point me in the direction of a sample Access booking system? Trying to build a booking system were customers can book a computer by date and timeslot, each timeslot having a limited amount of computers. Cheers for anyhelp, pointers given. PaulD
2
8240
by: Andy | last post by:
Hi folks I teach. At school, four IT rooms are booked using a paper based outline timetable. Completing it is easy but basic and impossible to ensure completion of all fields (name, year group, subject and software) and analysis of bookings is a nightmare. I just fancied pottering with Access, which I am pretty familiar with, to see if I could create a means of booking a room using a database. Locking a booking would then be a...
20
1690
by: bredal Jensen | last post by:
Hello gurus, I'm building a small booking system and i have come accross quiet a tedious pitfall. "I need to make sure that people do not book for tomorrow when todays time is greater or equal to 11."
0
1571
by: thegame21 | last post by:
Hi, I am currently creating a cinema system using access where a booking can be made for a event. Each event when it is shown is categoriesd as a performance. A booking must be made for each performamce. I have a constructed a query between the booking, event and peformance tables and created a subform on the booking form. The event table is linked to the performance table which in turn is linked to the booking table. I keep on getting the...
1
3217
by: simba | last post by:
Hello, I am currently doing a project which requires me to develop an online booking system for hotels and integrate both bed and room booking. I have the room booking working but I cant seem to get the bed booking working. I have dorm rooms with 8 beds in them and I would like to have a query(or something) which allows me to make the dorm rooms bed booked instead of room booked. Anyone any ideas on how to make this happen, anything would be...
3
2079
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I'm writing a booking system website, which needs a seat selection algorithm, my question is, if a user clicks on a seat (temporarily booking that one), how will the other users navigating on the same row of seats know that the previous user has already booked a specific seat? Perhaps a messaging system?
5
2753
by: Armenante | last post by:
Hi, I am creating a database for my A level project and i am stuck on the validation for the booking part of the database, and was just wondering if anyone could help me out? It is a plumbing booking and stock database in the booking section I have start date, start time and duration field. I want to add validation on the start date field as an after update event. Any ideas would be extremely helpful. Thank you. Tom
8
3020
by: shrimpeh | last post by:
Hi im currently messing around with creating a diary/booking system for a leisure centre. And im stuggling with how I can display all the data. The booking is taking the activity the customer is doing and the date and time etc. I want to display the data with each different activity having its own column and the rows having times. So that you can view a full day and see what is happening with each activity at all times of the day. Basically I...
3
3070
by: 88stevie | last post by:
Hi all, I have a system and I'm a little stuck. It's a booking system. It has rooms, etc and every room have a daily price. Then it has special daily rates when assigned. How do I calculate the total cost of a room if a daily rate exists?
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.