ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > Living Room

I'm thinking about learning how to program.

<< < (6/16) > >>

Renegade:
Well, I just finished booking air tickets to Vietnam, and thought I'd write a little program to illustrate some simple concepts and have some fun. Hopefully this will prove to be both fun and educational in starting to learn how to program in C#! :D

It should also prove just how fast and productive C# is, because you can create an entire online air ticket booking system in only a few minutes and in less than 100 lines of code! See! C# ROCKS~! :P

What I've come up with is a program that perfectly mimics what I get from the Quantas online air ticket reservation system. Oh, did I mention that I'm flying with Singapore air? ;)

The project is a very simple console application that demonstrates the use of:


* while
* WriteLine
* ReadLine
* if... then... else...
* string.ToLower()
* string.Substring(startAtIndex, length)
* the "+=" addition operator

--- Code: C# ---using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace ReserveQuantasTickets{    class Program    {        static void Main(string[] args)        {            int price = 450;            while (true) // This perfectly mimics the functionality of the Quantas online ticket reservation system.            {                Console.WriteLine("********************************************************");                Console.WriteLine("******** Welcome to Quantas flight booking *************");                Console.WriteLine("********************************************************");                Console.WriteLine("Please enter your name the press Enter."); // User-friendly communications                if (UserIsFedUp()) break;  // Notice that we don't actually store the name as it is unimportant.                Console.WriteLine("Please enter your point of departure.");                if (UserIsFedUp()) break;  // Notice that the departure point is also unimportant.                Console.WriteLine("Please enter your destination.");                if (UserIsFedUp()) break;  // Notice that the destination is also unimportant.                Console.WriteLine("Please enter your departure date.");                if (UserIsFedUp()) break;  // Notice that the departure date is also unimportant.                Console.WriteLine("Please enter your return date.");                if (UserIsFedUp()) break;  // Notice that the return date is also unimportant.                Console.WriteLine("Please enter your departure date.");                if (UserIsFedUp()) break;  // Notice that the departure date is also unimportant.                Console.WriteLine(string.Format("Your tickets will cost: {0}", price+=50)); // Notice that we don't care about anything other than increasing the price.                Console.WriteLine("Press Enter to proceed to payment...");                if (UserIsFedUp()) break;                 // The following is the actual error from the Quantas web site.                Console.WriteLine("Please review the following items");                Console.WriteLine("* We are unable to confirm the fare for the flights you have selected. Please cancel these segments and choose a different fare or flights and resubmit your confirmation request. (15012)");                Console.WriteLine("Press Enter to \"Start over\"");                if (UserIsFedUp()) break;             }        }         private static bool UserIsFedUp() // Notice that this is static.        {            if (Console.ReadLine().ToLower().Substring(0, 8) == "expletive") // Make sure to allow for exclamation marks.            {                return true;            }            else            {                return false;            }        }    }}
:D

ReserveQuantasTickets.zip (41.35 kB - downloaded 189 times.)

mouser:
 ;D ;D ;D ;D

Perry Mowbray:
What I've come up with is a program that perfectly mimics what I get from the Quantas online air ticket reservation system.
-Renegade (October 27, 2010, 09:37 PM)
--- End quote ---

...our national airline are a self-centered bunch: there is no "u" in QANTAS  :)

kyrathaba:
Cute!

Also, since you're just beginning with C#, I'll point out that often-times the boilerplate code inserts using lines that you don't need.  In your program, you should be able to delete the following two lines without problems:


--- ---using System.Collections.Generic;
using System.Linq;

phitsc:
Cute!

Also, since you're just beginning with C#, I'll point out that often-times the boilerplate code inserts using lines that you don't need.  In your program, you should be able to delete the following two lines without problems:


--- ---using System.Collections.Generic;
using System.Linq;-kyrathaba (October 28, 2010, 07:17 AM)
--- End quote ---

That depends on if he's using any generic collections or LINQ ;). Better: right-click anywhere in your C# code file, select 'Organize Usings', then 'Remove and Sort'.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version