using System;
using System.Collections.Generic;
using System.Text;
namespace Assessment
{
public class Flight
//details of the flight
{
private string flightNo;
private string flightName;
private string Date;
private string Time;
private string Origin;
private string Destination;
private double Total; // This is the running total revenue for the flight
private int State;
private const int AvailableBookings = 1;
private const int CheckingIn = 2;
private const int boarding = 3;
private const int closed = 4;
private const double seatValue = 150.00; // value of a seat
struct BookedSeats
{
public string SeatName;
public int passengerNo;
};
// Array for seat plan
BookedSeats[] Seats = new BookedSeats[32];
// initialise seatplan array
public void initArray()
{
for (int i = 0; i < 32; i++)
{
// set the seat name
Seats[i].SeatName = ((i % 8) + 1).ToString();
// append the seat letter
if (i < 8)
{
Seats[i].SeatName = Seats[i].SeatName + "A";
}
if (i >= 8 && i < 16)
{
Seats[i].SeatName = Seats[i].SeatName + "B";
}
if (i >= 16 && i < 24)
{
Seats[i].SeatName = Seats[i].SeatName + "C";
}
if (i >= 24 && i < 32)
{
Seats[i].SeatName = Seats[i].SeatName + "D";
}
// set the passenger number to zero
Seats[i].passengerNo = 0;
}
}
// testing purposes
public void printArray()
{
for (int i = 0; i < 32; i++)
{
Console.Write("seatName: " + Seats[i].SeatName + "\n");
}
}
// constructor
public Flight(string newname, string newnumber, string newdate, string newtime, string neworigin, string newdestination)
{
//details of Flight
flightName = newname;
flightNo = newnumber;
Date = newdate;
Time = newtime;
Origin = neworigin;
Destination = newdestination;
Total = 0.00;
State = AvailableBookings;
}
// cancel method
public Boolean CancelSeat(string SeatName, int passengerNo)
{
// dont take money off total as no refund policy
return true;
}
// booking method
public Boolean BookSeat(string SeatName, int passengerNo)
{
Boolean booked = false; // default is false
//because there are 32 seats, look in every seat until we find the desired seat
// check for state equals checking in or available for bookings
if (State == CheckingIn || State == AvailableBookings)
{
for (int i = 0; i < 32; i++)
{
if (Seats[i].SeatName.Equals(SeatName))
{
// check if booked
if (Seats[i].passengerNo > 0)
{
//if passengerNo is not 0 then it is booked
booked = false;
break;
}
else
{
//if passengerNo is 0 then it is not booked
Seats[i].passengerNo = passengerNo;//seat is now booked for this passenger
booked = true;
Total = Total + seatValue;
break;
}
}
}
}
// if booked = false then flight is full and flight is closed
if (booked == false)
{
State = closed;
}
return booked;
}
// reservation method
public Boolean ReserveSeat(string SeatName, int passengerNo)
{
return true;
}
}
public class Passenger //details of Passenger
{
private int No;
private string Name;
private string Address;
public int getNumber()
{
return No;
}
public void setNumber(int num)
{
No = num;
}
public string getName()
{
return Name;
}
public void setName(String nm)
{
Name = nm;
}
public string getAddress()
{
return Address;
}
public void setAddress(String add)
{
Address = add;
}
public Passenger(int newNo, string newname, string newaddress)
{
No = newNo;
Name = newname;
Address = newaddress;
}
public virtual int GetDiscount(bool promo)
{
if (promo)
return 5;
return 0;
}
}
public class businessPass : Passenger
// details of business passenger inherits details from Passenger and details company - Polymorphism
{
private string Company;
public businessPass(int num, String name, String addy, String newCompany) : base (num, name, addy)
{
Company = newCompany;
}
public override int GetDiscount(bool promo)
{
return 25;
}
}
public class IslandPass : Passenger
// details of IslandPassenger inherits details from Passenger and details Island
{
public string Island;
public IslandPass(int num, String name, String addy, string newIsland) : base (num, name, addy)
{
Island = newIsland;
}
public override int GetDiscount(bool promo)
{
return 10;
}
}
public class Interface
{
// variables
int numberOfFlights = 0;
Flight[] flightArray = new Flight[10]; // ten flights
// methods
// main interface
public void runMain()
{
Console.WriteLine("****************************************************************");
Console.WriteLine("*************** AIRLINE RESERVATION SYSTEM *************");
Console.WriteLine("* *");
Console.WriteLine("* Please choose an option: *");
Console.WriteLine("* *");
Console.WriteLine("* C - Create a flight *");
Console.WriteLine("* B - Book a seat *");
Console.WriteLine("* D - Display a booking *");
Console.WriteLine("* X - Cancel a seat *");
Console.WriteLine("* R - Reserve a seat *");
Console.WriteLine("* F - Check available seats *");
Console.WriteLine("* G - Get revenue for a flight *");
Console.WriteLine("* Z - Close a flight *");
Console.WriteLine("* Q - QUIT *");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("****************************************************************");
char temp;
temp = (char)Console.Read();
switch (temp)
{
case 'c':
// create a flight
createFlight();
break;
case 'd':
// display booking
displayBooking();
break;
case 'b':
// book a seat
runMain();
break;
case 'x':
// cancel a seat
runMain();
break;
case 'r':
// reserve a seat
runMain();
break;
case 'f':
// check available seats
runMain();
break;
case 'g':
// get revenue for a flight
runMain();
break;
case 'z':
// close a flight
runMain();
break;
case 'q':
// quit the program;
Console.WriteLine("You have chosen to quit the program, all data will be lost!");
Console.WriteLine("Press any key to continue");
Console.ReadLine();
Environment.Exit(1);
break;
default:
Console.WriteLine("Command not recognised");
runMain();
break;
}
}
// create flight
public void createFlight()
{
string flightname;
string flightnumber;
string flightdate;
string flighttime;
string flightorigin;
string flightdestination;
float total;
Console.WriteLine("Flight name: ");
flightname = Console.ReadLine();
Console.WriteLine("Flight number: ");
flightnumber = Console.ReadLine();
Console.WriteLine("Flight Date: ");
flightdate = Console.ReadLine();
Console.WriteLine("Flight Time: ");
flighttime = Console.ReadLine();
Console.WriteLine("Flight Origin: ");
flightorigin = Console.ReadLine();
Console.WriteLine("Flight Destination: ");
flightdestination = Console.ReadLine();
Console.WriteLine("Total cost of Flight");
// check array for existing flights and add new flight
if (numberOfFlights < 10)
{
flightArray[numberOfFlights + 1] = new Flight(flightname, flightnumber, flightdate, flighttime, flightorigin, flightdestination);
}
}
// create booking
public void createBooking()
{
string bookingpassname;
int bookingpassnumber;
string passaddress;
Boolean islandpassenger;
Boolean buspassenger;
Boolean standardpasspromo;
Console.WriteLine ("Passenger Name: ");
bookingpassname = Console.ReadLine();
Console.WriteLine ("Passeger Number: ");
bookingpassnumber = 0;
Console.WriteLine("Passenger Address: ");
passaddress = Console.ReadLine();
Console.WriteLine("Island Passenger Y/N: ");
islandpassenger = false;
Console.WriteLine("Business Passenger Y/N: ");
buspassenger = false;
Console.WriteLine("Promo Y/N: ");
standardpasspromo = false;
//Discount applied
if (buspassenger == true)
{
Console.WriteLine("Apply 25% Discount");
}
else if (islandpassenger==true)
{
Console.WriteLine ("Apply 10% discount");
}
else if (standardpasspromo==true)
{
Console.WriteLine ("Apply 5% discount");
}
else
{
Console.WriteLine ("Standard Fare applied");
}
}
// cancel booking
public void cancelBooking()
{
string cancelseatname;
string cancelpassname;
Console.WriteLine ("Cancel Seat Name: ");
cancelseatname = Console.ReadLine();
Console.WriteLine ("Passenger Name: ");
cancelpassname = Console.ReadLine();
}
// reserve seat
public void reserveSeat()
{
string reserveseatname;
string reservepassname;
Console.WriteLine("Resereve Seat: ");
reserveseatname = Console.ReadLine();
Console.WriteLine("Passenger Name: ");
reservepassname = Console.ReadLine();
}
// revenue for flight
public void flightrevenue()
{
double flightprice;
double totalflighprice;
flightprice = fprice;
totalflightprice = totalprice;
costofflight = fprice + totalprice;
Console.WriteLine ("Total Revenue for Flight ");
totalflighprice = Console.ReadLine();
}
// close flight
public void closeflight();
{
}
class program
{
static void Main(string[] args)
{
Interface main = new Interface();
main.runMain();
}
}
}
Can't get my project code to workAirline Reservation code
Page 1 of 1
6 Replies - 1680 Views - Last Post: 10 June 2009 - 05:40 PM
#1
Can't get my project code to work
Posted 10 June 2009 - 09:53 AM
Replies To: Can't get my project code to work
#2
Re: Can't get my project code to work
Posted 10 June 2009 - 09:56 AM
public void flightrevenue()
{
double flightprice;
double totalflighprice;
flightprice = fprice;
totalflightprice = totalprice;
costofflight = fprice + totalprice;
Console.WriteLine ("Total Revenue for Flight ");
totalflighprice = Console.ReadLine();
}
Where are you wanting to get all of those variables from (fprice, totalprice)?
#3
Re: Can't get my project code to work
Posted 10 June 2009 - 11:42 AM
MageUK, on 10 Jun, 2009 - 08:56 AM, said:
public void flightrevenue()
{
double flightprice;
double totalflighprice;
flightprice = fprice;
totalflightprice = totalprice;
costofflight = fprice + totalprice;
Console.WriteLine ("Total Revenue for Flight ");
totalflighprice = Console.ReadLine();
}
Where are you wanting to get all of those variables from (fprice, totalprice)?
Your right, not sure what i was doing there.....i guess i was trying to work out the cost of flights......
#4
Re: Can't get my project code to work
Posted 10 June 2009 - 11:46 AM
GeekGhirl, on 10 Jun, 2009 - 10:42 AM, said:
MageUK, on 10 Jun, 2009 - 08:56 AM, said:
public void flightrevenue()
{
double flightprice;
double totalflighprice;
flightprice = fprice;
totalflightprice = totalprice;
costofflight = fprice + totalprice;
Console.WriteLine ("Total Revenue for Flight ");
totalflighprice = Console.ReadLine();
}
Where are you wanting to get all of those variables from (fprice, totalprice)?
Your right, not sure what i was doing there.....i guess i was trying to work out the cost of flights......
Sarcasm much? I said where are you wanting to get the variables from? Where is fprice meant to come from? I don't actually see anything relating to price in your code...
#5
Re: Can't get my project code to work
Posted 10 June 2009 - 11:52 AM
This post has been edited by papuccino1: 10 June 2009 - 11:53 AM
#6
Re: Can't get my project code to work
Posted 10 June 2009 - 01:10 PM
papuccino1, on 10 Jun, 2009 - 10:52 AM, said:
Have taken that out - not sure what i was trying to do there....#
Basic i am trying to create a flight, with flight no etc and create a booking from one place to another, diplaying the available seats, when booked the cost gets added for each booking made. If there is a specific passenger, like business passenger they get discount 25, 10, or 5% - and the idea is to get it running and get a total cost for each flight.....i put in a condition that there will be 10 flights on this route....at a cost £150 per flight....
what else do i need to do to make it work....had a friend helping me, but not sure what to do next....(just a beginner with c#)...
any help in pointing out what i need to do next would be fab, to get it working....cheers guys...
using System;
using System.Collections.Generic;
using System.Text;
namespace Assessment
{
public class Flight
//details of the flight
{
private string flightNo;
private string flightName;
private string Date;
private string Time;
private string Origin;
private string Destination;
private double Total; // This is the running total revenue for the flight
private int State;
private const int AvailableBookings = 1;
private const int CheckingIn = 2;
private const int boarding = 3;
private const int closed = 4;
private const double seatValue = 150.00; // value of a seat
struct BookedSeats
{
public string SeatName;
public int passengerNo;
};
// Array for seat plan
BookedSeats[] Seats = new BookedSeats[32];
// initialise seatplan array
public void initArray()
{
for (int i = 0; i < 32; i++)
{
// set the seat name
Seats[i].SeatName = ((i % 8) + 1).ToString();
// append the seat letter
if (i < 8)
{
Seats[i].SeatName = Seats[i].SeatName + "A";
}
if (i >= 8 && i < 16)
{
Seats[i].SeatName = Seats[i].SeatName + "B";
}
if (i >= 16 && i < 24)
{
Seats[i].SeatName = Seats[i].SeatName + "C";
}
if (i >= 24 && i < 32)
{
Seats[i].SeatName = Seats[i].SeatName + "D";
}
// set the passenger number to zero
Seats[i].passengerNo = 0;
}
}
// testing purposes
public void printArray()
{
for (int i = 0; i < 32; i++)
{
Console.Write("seatName: " + Seats[i].SeatName + "\n");
}
}
// constructor
public Flight(string newname, string newnumber, string newdate, string newtime, string neworigin, string newdestination)
{
//details of Flight
flightName = newname;
flightNo = newnumber;
Date = newdate;
Time = newtime;
Origin = neworigin;
Destination = newdestination;
Total = 0.00;
State = AvailableBookings;
}
// cancel method
public Boolean CancelSeat(string SeatName, int passengerNo)
{
// dont take money off total as no refund policy
return true;
}
// booking method
public Boolean BookSeat(string SeatName, int passengerNo)
{
Boolean booked = false; // default is false
//because there are 32 seats, look in every seat until we find the desired seat
// check for state equals checking in or available for bookings
if (State == CheckingIn || State == AvailableBookings)
{
for (int i = 0; i < 32; i++)
{
if (Seats[i].SeatName.Equals(SeatName))
{
// check if booked
if (Seats[i].passengerNo > 0)
{
//if passengerNo is not 0 then it is booked
booked = false;
break;
}
else
{
//if passengerNo is 0 then it is not booked
Seats[i].passengerNo = passengerNo;//seat is now booked for this passenger
booked = true;
Total = Total + seatValue;
break;
}
}
}
}
// if booked = false then flight is full and flight is closed
if (booked == false)
{
State = closed;
}
return booked;
}
// reservation method
public Boolean ReserveSeat(string SeatName, int passengerNo)
{
return true;
}
}
public class Passenger //details of Passenger
{
private int No;
private string Name;
private string Address;
public int getNumber()
{
return No;
}
public void setNumber(int num)
{
No = num;
}
public string getName()
{
return Name;
}
public void setName(String nm)
{
Name = nm;
}
public string getAddress()
{
return Address;
}
public void setAddress(String add)
{
Address = add;
}
public Passenger(int newNo, string newname, string newaddress)
{
No = newNo;
Name = newname;
Address = newaddress;
}
public virtual int GetDiscount(bool promo)
{
if (promo)
return 5;
return 0;
}
}
public class businessPass : Passenger
// details of business passenger inherits details from Passenger and details company - Polymorphism
{
private string Company;
public businessPass(int num, String name, String addy, String newCompany) : base (num, name, addy)
{
Company = newCompany;
}
public override int GetDiscount(bool promo)
{
return 25;
}
}
public class IslandPass : Passenger
// details of IslandPassenger inherits details from Passenger and details Island
{
public string Island;
public IslandPass(int num, String name, String addy, string newIsland) : base (num, name, addy)
{
Island = newIsland;
}
public override int GetDiscount(bool promo)
{
return 10;
}
}
public class Interface
{
// variables
int numberOfFlights = 0;
Flight[] flightArray = new Flight[10]; // ten flights
// methods
// main interface
public void runMain()
{
Console.WriteLine("****************************************************************");
Console.WriteLine("*************** SCOTIA AIRLINES RESERVATION SYSTEM *************");
Console.WriteLine("* *");
Console.WriteLine("* Please choose an option: *");
Console.WriteLine("* *");
Console.WriteLine("* C - Create a flight *");
Console.WriteLine("* B - Book a seat *");
Console.WriteLine("* D - Display a booking *");
Console.WriteLine("* X - Cancel a seat *");
Console.WriteLine("* R - Reserve a seat *");
Console.WriteLine("* F - Check available seats *");
Console.WriteLine("* G - Get revenue for a flight *");
Console.WriteLine("* Z - Close a flight *");
Console.WriteLine("* Q - QUIT *");
Console.WriteLine("* *");
Console.WriteLine("* *");
Console.WriteLine("****************************************************************");
char temp;
temp = (char)Console.Read();
switch (temp)
{
case 'c':
// create a flight
createFlight();
break;
case 'd':
// display booking
displayBooking();
break;
case 'b':
// book a seat
runMain();
break;
case 'x':
// cancel a seat
runMain();
break;
case 'r':
// reserve a seat
runMain();
break;
case 'f':
// check available seats
runMain();
break;
case 'g':
// get revenue for a flight
runMain();
break;
case 'z':
// close a flight
runMain();
break;
case 'q':
// quit the program;
Console.WriteLine("You have chosen to quit the program, all data will be lost!");
Console.WriteLine("Press any key to continue");
Console.ReadLine();
Environment.Exit(1);
break;
default:
Console.WriteLine("Command not recognised");
runMain();
break;
}
}
// create flight
public void createFlight()
{
string flightname;
string flightnumber;
string flightdate;
string flighttime;
string flightorigin;
string flightdestination;
Console.WriteLine("Flight name: ");
flightname = Console.ReadLine();
Console.WriteLine("Flight number: ");
flightnumber = Console.ReadLine();
Console.WriteLine("Flight Date: ");
flightdate = Console.ReadLine();
Console.WriteLine("Flight Time: ");
flighttime = Console.ReadLine();
Console.WriteLine("Flight Origin: ");
flightorigin = Console.ReadLine();
Console.WriteLine("Flight Destination: ");
flightdestination = Console.ReadLine();
// check array for existing flights and add new flight
if (numberOfFlights < 10)
{
flightArray[numberOfFlights + 1] = new Flight(flightname, flightnumber, flightdate, flighttime, flightorigin, flightdestination);
}
}
// create booking
public void createBooking()
{
string bookingpassname;
string passaddress;
Boolean islandpassenger;
Boolean buspassenger;
Boolean standardpasspromo;
Console.WriteLine ("Passenger Name: ");
bookingpassname = Console.ReadLine();
Console.WriteLine ("Passeger Number: ");
Console.WriteLine("Passenger Address: ");
passaddress = Console.ReadLine();
Console.WriteLine("Island Passenger Y/N: ");
islandpassenger = false;
Console.WriteLine("Business Passenger Y/N: ");
buspassenger = false;
Console.WriteLine("Promo Y/N: ");
standardpasspromo = false;
//Discount applied
if (buspassenger == true)
{
Console.WriteLine("Apply 25% Discount");
}
else if (islandpassenger==true)
{
Console.WriteLine ("Apply 10% discount");
}
else if (standardpasspromo==true)
{
Console.WriteLine ("Apply 5% discount");
}
else
{
Console.WriteLine ("Standard Fare applied");
}
}
// cancel booking
public void cancelBooking()
{
string cancelseatname;
string cancelpassname;
Console.WriteLine ("Cancel Seat Name: ");
cancelseatname = Console.ReadLine();
Console.WriteLine ("Passenger Name: ");
cancelpassname = Console.ReadLine();
}
// reserve seat
public void reserveSeat()
{
string reserveseatname;
string reservepassname;
Console.WriteLine("Reserve Seat: ");
reserveseatname = Console.ReadLine();
Console.WriteLine("Passenger Name: ");
reservepassname = Console.ReadLine();
}
/*
* The Following method was needed for compilation
*/
//Display booking
public void displayBooking()
{
string showseats;
Console.WriteLine("List of Available Seats");
showseats = Console.ReadLine();
}
// revenue for flight
public void flightrevenue()
{
double totalflighprice;
Console.WriteLine ("Total Revenue for Flight ");
totalflighprice = double.Parse(Console.ReadLine());
}
// close flight
public void closeflight()
{
}
}
class program
{
static void Main(string[] args)
{
Interface main = new Interface();
main.runMain();
}
}
}
MageUK, on 10 Jun, 2009 - 10:46 AM, said:
GeekGhirl, on 10 Jun, 2009 - 10:42 AM, said:
MageUK, on 10 Jun, 2009 - 08:56 AM, said:
public void flightrevenue()
{
double flightprice;
double totalflighprice;
flightprice = fprice;
totalflightprice = totalprice;
costofflight = fprice + totalprice;
Console.WriteLine ("Total Revenue for Flight ");
totalflighprice = Console.ReadLine();
}
Where are you wanting to get all of those variables from (fprice, totalprice)?
Your right, not sure what i was doing there.....i guess i was trying to work out the cost of flights......
Sarcasm much? I said where are you wanting to get the variables from? Where is fprice meant to come from? I don't actually see anything relating to price in your code...
No wasn't honestly being sarcastic i believe it was an error putting those pflight in.....i just didn't know what i was doing there...honest answer not sarcasm, certainly wouldn't be sarcastic if i was looking for help...
#7
Re: Can't get my project code to work
Posted 10 June 2009 - 05:40 PM
Console.WriteLine("* C - Create a flight *");
Console.WriteLine("* B - Book a seat *");
Console.WriteLine("* D - Display a booking *");
Console.WriteLine("* X - Cancel a seat *");
Console.WriteLine("* R - Reserve a seat *");
Console.WriteLine("* F - Check available seats *");
Console.WriteLine("* G - Get revenue for a flight *");
Console.WriteLine("* Z - Close a flight *");
We might be able to help you better if you tell us what is working and what is not. What of the above menu choices is working? Can you create a new flight? Can you book a seat? etc.
Are you wanting of adding more features?
I would suggest organizing your code a little better. You are using classes, which is good to see, but having them all lumped together in one file can be a little confusing (that is just a personal preference though, not something you really need to do.) I would also suggest working on one class at a time. Try to get one class to work as you want it to instead of all of them working at once. For example, get your Passenger class to do what you want it to do, then work on the inherited classes. There is an article in the C# Programmers forum about Unit testing. You can use that to test if your class is working the way it is supposed to work.
*EDIT*
It is usually a good idea to separate programming logic from business logic. Can't think of a way to explain that better at the moment. Here is one though, the discounts for passengers is business logic. Creating new passengers is programming logic.
This post has been edited by SixOfEleven: 10 June 2009 - 05:45 PM
|
|

New Topic/Question
Reply




MultiQuote





|