SlideShare a Scribd company logo
Create a Flight class that uses the Plane and Time class. This class will represent a flight between
two airports, using a specific Plane, and departing at a specific Time. It should contain a
constructor, 7 instance variables (plane, flight number, cost, departure, duration, source,
destination), and 9 methods (see below).
Below is the code so far (only part of the final test FLIGHT is missing):
/**
*
* @author (your name), Acuna
*/
public class Driver {
public static void main(String[] args) {
testAirline();
testAirport();
testPlane();
testTime();
testFlight();
}
public static void testAirline() {
System.out.println("==testAirline()==");
Airline a1 = Airline.American;
Airline a2 = Airline.United;
Airline a3 = Airline.Delta;
Airline a4 = Airline.United;
System.out.println("a1: " + a1);
System.out.println("a2 == a3: " + (a1 == a2));
System.out.println("a2 == a4: " + (a2 == a4));
}
public static void testAirport() {
System.out.println("==testAirport()==");
Airport a1 = Airport.PHX;
Airport a2 = Airport.LAX;
Airport a3 = Airport.SFO;
Airport a4 = Airport.NRT;
Airport a5 = Airport.SIN;
System.out.println("a1: " + a1);
System.out.println("a2 == a3: " + (a1 == a2));
System.out.println("a2 == a4: " + (a2 == a4));
System.out.println("a1: " + Airport.getAirportCity(a1));
System.out.println("a3: " + Airport.getAirportCity(a3));
System.out.println("a5: " + Airport.getAirportCity(a5));
}
public static void testPlane() {
System.out.println("==testPlane()==");
Plane p1 = new Plane(Airline.Delta, "Boeing 717");
Plane p2 = new Plane(Airline.United, "Airbus A321");
System.out.println(p1.getAirline());
System.out.println(p1.getModel());
System.out.println(p1);
System.out.println(p2);
}
public static void testTime() {
System.out.println("==testTime()==");
//Test 1: use default constructor.
Time t1 = new Time();
//Test 2: use overloaded constructor.
Time t2 = new Time(9, 0);
Time t3 = new Time(1, 15);
//Test 3: use clone operation.
Time t4 = t3.getCopy();
//Test 4: run toString on AM times.
System.out.println(new Time(0, 5));
System.out.println(new Time(1, 15));
System.out.println(new Time(2, 45));
System.out.println(new Time(10, 5));
System.out.println(new Time(11, 15));
//Test 5: run toString on PM times.
System.out.println(new Time(12, 45));
System.out.println(new Time(13, 5));
System.out.println(new Time(22, 15));
System.out.println(new Time(23, 45));
//Test 6: run toString on object from default constructor.
System.out.println("t1: " + t1);
//Test 7: testing addTime operation
System.out.println("t2: " + t2);
t2.addTime(t3);
System.out.println("t2: " + t2);
//Test 8: testing addMinutes operation
t2.addMinute(181);
System.out.println("t2: " + t2);
//Test 9: testing8 addHours operation
t2.addHours(2);
System.out.println("t2: " + t2);
//Test 10: testing cloned copy.
t4.addHours(1);
System.out.println("t3: " + t3);//original
System.out.println("t4: " + t4);//clone
//Test 11: testing isEarlierThan.
System.out.println("t3 < t4: " + t3.isEarlierThan(t4));
System.out.println("t4 < t3: " + t4.isEarlierThan(t3));
System.out.println("t2 < t4: " + t2.isEarlierThan(t4));
System.out.println("t4 < t2: " + t4.isEarlierThan(t2));
System.out.println("t2 < t2: " + t2.isEarlierThan(t2));
//Test 12: testing isLaterThan.
System.out.println("t2 > t4: " + t2.isLaterThan(t4));
System.out.println("t4 > t2: " + t4.isLaterThan(t2));
System.out.println("t4 > t4: " + t4.isLaterThan(t4));
//Test 13: testing isSameTime.
System.out.println("t2 = t4: " + t2.isSameTime(t4));
System.out.println("t4 = t4: " + t4.isSameTime(t4));
System.out.println("t4 = 2:15AM: " + t4.isSameTime(new Time(2, 15)));
}
public static void testFlight() {
System.out.println("==testFlight()==");
Flight f1 = new Flight(new Plane(Airline.American, "Airbus A321"),
"495",
79,
new Time(11,5), 100,
Airport.PHX, Airport.LAX);
Flight f2 = new Flight(new Plane(Airline.Delta, "Boeing 717"),
"1063",
79,
new Time(7, 10),
95,
Airport.PHX,
Airport.LAX);
Flight f3 = new Flight(new Plane(Airline.American, "Airbus A321"),
"400",
44,
new Time(21, 25),
127,
Airport.PHX,
Airport.SFO);
Flight f4 = new Flight(new Plane(Airline.United, "Boeing 787"),
"400",
525,
new Time(10, 50),
715,
Airport.LAX,
Airport.NRT);
Flight f5 = new Flight(new Plane(Airline.United, "Boeing 737"),
"414",
59,
new Time(6, 50),
85,
Airport.LAX,
Airport.SFO);
System.out.println(f1.toDetailedString());
System.out.println();
System.out.println(f1.toOverviewString());
System.out.println();
System.out.println();
System.out.println(f5.toDetailedString());
System.out.println();
System.out.println(f5.toOverviewString());
}
}
Solution
#include
#include
#define MAX_NUM_SEATS (20)
#define MAX_NUM_SEATS_IN_FIRST_CLASS (5)
#define MAX_NUM_SEATS_IN_ECONOMY (MAX_NUM_SEATS -
MAX_NUM_SEATS_IN_FIRST_CLASS)
int main()
{
int plane[MAX_NUM_SEATS] = {0}, i=0;
int nNumSeatsInFirst = 0;
int nNumSeatsInEconomy = 0;
int nSeatAssignmentFirstClass = 1; // start at 1;
int nSeatAssignmentEconomy = MAX_NUM_SEATS_IN_FIRST_CLASS + 1; // start at 6
int choice;
int nClass;
int nCurrentSeatAssignment;// firstClass=1,economy=6,choice;
char response[2];
char firstname[35], lastname[35];
int bPrintTicket;
while( i < MAX_NUM_SEATS )
{
printf(" %s %s ", "Please type 1 for "First class"","Please type 2
for"Economy"");
scanf("%d", &choice);
if( !( ( 1 == choice ) || ( 2 == choice ) ) )
{
continue;
}
// start out assuming we will print ticket!
bPrintTicket = 1;
printf(" Enter first name:");
scanf("%s",firstname);
printf(" Enter lastname :");
scanf("%s", lastname);
nClass = choice; // store the class before doing all the logical checks
/****************************************************************/
/*************** ECONOMY SECTION ***************/
/****************************************************************/
if( 2 == choice )
{
// check for economy full
if( nNumSeatsInEconomy >= MAX_NUM_SEATS_IN_ECONOMY )
{
// economy full
// check for first class (plane ) full
if( nNumSeatsInFirst <= MAX_NUM_SEATS_IN_FIRST_CLASS )
{
printf("The economy section is full. ");
printf("would you like to sit in first class ");
printf("section( Y or N)?");
scanf("%s", response);
if ( toupper(response[0])=='Y')
{
// print ticket!
bPrintTicket = 1;
printf( "Your seat assignment is %d ", nSeatAssignmentFirstClass );
nCurrentSeatAssignment = nSeatAssignmentFirstClass;
plane[nSeatAssignmentFirstClass - 1] = 1;
nSeatAssignmentFirstClass++;
nNumSeatsInFirst++;
nClass = 1;
i++;
}
else
{
// don't print ticket!
bPrintTicket = 0;
printf("Next flight leaves in 3 hours. ");
}
}
else
{
// don't print ticket!
bPrintTicket = 0;
// print out that plane is full
printf("Plane is full, next flight in 3 hours ");
}
}
else
{
// economy is not full
printf("Your seat assignment is %d ", nSeatAssignmentEconomy );
plane[(nSeatAssignmentEconomy - 1)] = 1;
nCurrentSeatAssignment = nSeatAssignmentEconomy;
nSeatAssignmentEconomy++;
nNumSeatsInEconomy++;
i++;
}
} // if( choice == 2 )
/****************************************************************/
/*************** FIRST CLASS SECTION ***************/
/****************************************************************/
if( 1 == choice )
{
// check for fisrt class full
if( nNumSeatsInFirst >= MAX_NUM_SEATS_IN_FIRST_CLASS )
{
// first class full
// check for economy class (plane) full
if( nNumSeatsInEconomy <= MAX_NUM_SEATS_IN_ECONOMY )
{
printf("The First Class section is full. ");
printf("Would you like to sit in the economy ");
printf("section (Y or N)?");
scanf("%s", response);
if(toupper(response[0])=='Y')
{
printf("Your seat assignment is %d ",nSeatAssignmentEconomy);
plane[nSeatAssignmentEconomy - 1] = 1;
nCurrentSeatAssignment = nSeatAssignmentEconomy;
nSeatAssignmentEconomy++;
nNumSeatsInEconomy++;
i++;
nClass = 2;
}
else
{
// don't print ticket!
bPrintTicket = 0;
printf("Next flight leaves in 3 hours. ");
}
}
else
{
// don't print ticket!
bPrintTicket = 0;
// print out that plane is full
printf("Plane is full, next flight in 3 hours ");
}
}
else
{
// first is not full
printf("Your seat assignment is %d ", nSeatAssignmentFirstClass );
plane[(nSeatAssignmentFirstClass - 1)] = 1;
nCurrentSeatAssignment = nSeatAssignmentFirstClass;
nSeatAssignmentFirstClass++;
nNumSeatsInFirst++;
i++;
}
}
if( 1 == bPrintTicket )
{
printf(" **************************************** ");
printf(" * * ");
printf(" NAME:%s, %s  ",lastname,firstname);
printf(" * * ");
printf(" CLASS:%d  ",nClass);
printf(" * * ");
printf(" SEAT:%d  ",nCurrentSeatAssignment);
printf(" * * ");
printf("  ");
printf(" **************************************** ");
}
}
printf(" All the seats for this flight are sold ");
return 0;
}

More Related Content

PDF
In this assignment you will practice creating classes and enumeratio.pdf
PDF
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
DOC
Csci 1101 computer science ii assignment 3/tutorialoutlet
PDF
A06
PDF
JAVA The file being read is called flightdatatxt please in.pdf
PDF
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
DOCX
#include Status.hnamespace sdds{StatusStatus(c
DOCX
#include Status.hnamespace sdds{StatusStatus(c
In this assignment you will practice creating classes and enumeratio.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
Csci 1101 computer science ii assignment 3/tutorialoutlet
A06
JAVA The file being read is called flightdatatxt please in.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
#include Status.hnamespace sdds{StatusStatus(c
#include Status.hnamespace sdds{StatusStatus(c

Similar to Create a Flight class that uses the Plane and Time class. This class.pdf (20)

DOCX
Cs project
PDF
Computer Investgatort Project (HOTEL MANAGEMENT SYSTEM)
PDF
1 Write a program that creates an Integer class Date which .pdf
PDF
Time.java public class Time {    private int hour; 0 - 2.pdf
DOCX
You work for an airline, a small airline, so small you have only one.docx
DOCX
computer science project on movie booking system
DOCX
Hw12 refactoring to factory method
PDF
Java programing please help me. Hello, I tried making a Class Flight.pdf
PDF
Can you please debug this Thank you in advance! This program is sup.pdf
PDF
Please dont answer if you cannot complete all the requirements. Th.pdf
DOCX
simple-movie-ticket-booking-system-1
PDF
public class Passenger {    public static enum Section {        .pdf
DOCX
This lab must be finished in the lab period. Write a class named Fan .docx
PDF
An airline uses a computer system to maintain flight sales informa.pdf
PDF
Section5 containment in unions and methods
DOCX
need help with this code#include #include #include #includ.docx
PDF
Write a class that implements the BagInterface. BagInterface should .pdf
PDF
Need to make a Java program which calculates the number of days betw.pdf
DOCX
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
PDF
(C++) Change the following program so that it uses a dynamic array i.pdf
Cs project
Computer Investgatort Project (HOTEL MANAGEMENT SYSTEM)
1 Write a program that creates an Integer class Date which .pdf
Time.java public class Time {    private int hour; 0 - 2.pdf
You work for an airline, a small airline, so small you have only one.docx
computer science project on movie booking system
Hw12 refactoring to factory method
Java programing please help me. Hello, I tried making a Class Flight.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
Please dont answer if you cannot complete all the requirements. Th.pdf
simple-movie-ticket-booking-system-1
public class Passenger {    public static enum Section {        .pdf
This lab must be finished in the lab period. Write a class named Fan .docx
An airline uses a computer system to maintain flight sales informa.pdf
Section5 containment in unions and methods
need help with this code#include #include #include #includ.docx
Write a class that implements the BagInterface. BagInterface should .pdf
Need to make a Java program which calculates the number of days betw.pdf
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
(C++) Change the following program so that it uses a dynamic array i.pdf
Ad

More from daniamantileonismc36 (20)

PDF
Question 11What is defined as the set of protections put in place .pdf
PDF
Lichens exist with two symbionts living together. What two domainski.pdf
PDF
Investors are most concerned about reinvestment rate risk when bonds.pdf
PDF
httpimgur.comakA1IGplaese zoom in to read the question. thank.pdf
PDF
How does a traction epipphysis affect the shape of a boneSoluti.pdf
PDF
How are different isotopes of an element structurally the same and h.pdf
PDF
Drag each label to the appropriate position to indicate the action de.pdf
PDF
Discuss the role of a computer architect, LAN, WAN, and Internet..pdf
PDF
December 31, wind or paid the bil Janu ry 11. are paid a total of $3,.pdf
PDF
Corporal Mary Klink is domiciled in Virginia but stationed all year .pdf
PDF
A. True or False - Movement of water across the plasma membrane can .pdf
PDF
120 palatal aly fuss a leollnwten kh in higael dersin and Mornise.pdf
PDF
Which of the following best defines a trace a. used to monitor acti.pdf
PDF
What was the lasting significance of the Crusades your answer must .pdf
PDF
1. Screaming Pandas are a highly endangered if annoying creature tha.pdf
PDF
1.Which plants contain lignified vascular tissue (Select all that a.pdf
PDF
What relatively recent scientific advancement has made mapping by lin.pdf
PDF
What characteristic of information is satisfied by an original signe.pdf
PDF
What are pseudo-assembly instructions and what are they used for.pdf
PDF
The right nostril and right ear are __________.Im not quite sure.pdf
Question 11What is defined as the set of protections put in place .pdf
Lichens exist with two symbionts living together. What two domainski.pdf
Investors are most concerned about reinvestment rate risk when bonds.pdf
httpimgur.comakA1IGplaese zoom in to read the question. thank.pdf
How does a traction epipphysis affect the shape of a boneSoluti.pdf
How are different isotopes of an element structurally the same and h.pdf
Drag each label to the appropriate position to indicate the action de.pdf
Discuss the role of a computer architect, LAN, WAN, and Internet..pdf
December 31, wind or paid the bil Janu ry 11. are paid a total of $3,.pdf
Corporal Mary Klink is domiciled in Virginia but stationed all year .pdf
A. True or False - Movement of water across the plasma membrane can .pdf
120 palatal aly fuss a leollnwten kh in higael dersin and Mornise.pdf
Which of the following best defines a trace a. used to monitor acti.pdf
What was the lasting significance of the Crusades your answer must .pdf
1. Screaming Pandas are a highly endangered if annoying creature tha.pdf
1.Which plants contain lignified vascular tissue (Select all that a.pdf
What relatively recent scientific advancement has made mapping by lin.pdf
What characteristic of information is satisfied by an original signe.pdf
What are pseudo-assembly instructions and what are they used for.pdf
The right nostril and right ear are __________.Im not quite sure.pdf
Ad

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Institutional Correction lecture only . . .
PDF
Complications of Minimal Access Surgery at WLH
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Pharma ospi slides which help in ospi learning
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Cell Structure & Organelles in detailed.
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Classroom Observation Tools for Teachers
Microbial diseases, their pathogenesis and prophylaxis
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Institutional Correction lecture only . . .
Complications of Minimal Access Surgery at WLH
FourierSeries-QuestionsWithAnswers(Part-A).pdf
01-Introduction-to-Information-Management.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Pharma ospi slides which help in ospi learning
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Cell Structure & Organelles in detailed.
Chinmaya Tiranga quiz Grand Finale.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Classroom Observation Tools for Teachers

Create a Flight class that uses the Plane and Time class. This class.pdf

  • 1. Create a Flight class that uses the Plane and Time class. This class will represent a flight between two airports, using a specific Plane, and departing at a specific Time. It should contain a constructor, 7 instance variables (plane, flight number, cost, departure, duration, source, destination), and 9 methods (see below). Below is the code so far (only part of the final test FLIGHT is missing): /** * * @author (your name), Acuna */ public class Driver { public static void main(String[] args) { testAirline(); testAirport(); testPlane(); testTime(); testFlight(); } public static void testAirline() { System.out.println("==testAirline()=="); Airline a1 = Airline.American; Airline a2 = Airline.United; Airline a3 = Airline.Delta; Airline a4 = Airline.United; System.out.println("a1: " + a1); System.out.println("a2 == a3: " + (a1 == a2)); System.out.println("a2 == a4: " + (a2 == a4)); } public static void testAirport() { System.out.println("==testAirport()==");
  • 2. Airport a1 = Airport.PHX; Airport a2 = Airport.LAX; Airport a3 = Airport.SFO; Airport a4 = Airport.NRT; Airport a5 = Airport.SIN; System.out.println("a1: " + a1); System.out.println("a2 == a3: " + (a1 == a2)); System.out.println("a2 == a4: " + (a2 == a4)); System.out.println("a1: " + Airport.getAirportCity(a1)); System.out.println("a3: " + Airport.getAirportCity(a3)); System.out.println("a5: " + Airport.getAirportCity(a5)); } public static void testPlane() { System.out.println("==testPlane()=="); Plane p1 = new Plane(Airline.Delta, "Boeing 717"); Plane p2 = new Plane(Airline.United, "Airbus A321"); System.out.println(p1.getAirline()); System.out.println(p1.getModel()); System.out.println(p1); System.out.println(p2); } public static void testTime() { System.out.println("==testTime()=="); //Test 1: use default constructor. Time t1 = new Time(); //Test 2: use overloaded constructor. Time t2 = new Time(9, 0); Time t3 = new Time(1, 15);
  • 3. //Test 3: use clone operation. Time t4 = t3.getCopy(); //Test 4: run toString on AM times. System.out.println(new Time(0, 5)); System.out.println(new Time(1, 15)); System.out.println(new Time(2, 45)); System.out.println(new Time(10, 5)); System.out.println(new Time(11, 15)); //Test 5: run toString on PM times. System.out.println(new Time(12, 45)); System.out.println(new Time(13, 5)); System.out.println(new Time(22, 15)); System.out.println(new Time(23, 45)); //Test 6: run toString on object from default constructor. System.out.println("t1: " + t1); //Test 7: testing addTime operation System.out.println("t2: " + t2); t2.addTime(t3); System.out.println("t2: " + t2); //Test 8: testing addMinutes operation t2.addMinute(181); System.out.println("t2: " + t2); //Test 9: testing8 addHours operation t2.addHours(2); System.out.println("t2: " + t2); //Test 10: testing cloned copy. t4.addHours(1); System.out.println("t3: " + t3);//original
  • 4. System.out.println("t4: " + t4);//clone //Test 11: testing isEarlierThan. System.out.println("t3 < t4: " + t3.isEarlierThan(t4)); System.out.println("t4 < t3: " + t4.isEarlierThan(t3)); System.out.println("t2 < t4: " + t2.isEarlierThan(t4)); System.out.println("t4 < t2: " + t4.isEarlierThan(t2)); System.out.println("t2 < t2: " + t2.isEarlierThan(t2)); //Test 12: testing isLaterThan. System.out.println("t2 > t4: " + t2.isLaterThan(t4)); System.out.println("t4 > t2: " + t4.isLaterThan(t2)); System.out.println("t4 > t4: " + t4.isLaterThan(t4)); //Test 13: testing isSameTime. System.out.println("t2 = t4: " + t2.isSameTime(t4)); System.out.println("t4 = t4: " + t4.isSameTime(t4)); System.out.println("t4 = 2:15AM: " + t4.isSameTime(new Time(2, 15))); } public static void testFlight() { System.out.println("==testFlight()=="); Flight f1 = new Flight(new Plane(Airline.American, "Airbus A321"), "495", 79, new Time(11,5), 100, Airport.PHX, Airport.LAX); Flight f2 = new Flight(new Plane(Airline.Delta, "Boeing 717"), "1063", 79, new Time(7, 10), 95, Airport.PHX, Airport.LAX);
  • 5. Flight f3 = new Flight(new Plane(Airline.American, "Airbus A321"), "400", 44, new Time(21, 25), 127, Airport.PHX, Airport.SFO); Flight f4 = new Flight(new Plane(Airline.United, "Boeing 787"), "400", 525, new Time(10, 50), 715, Airport.LAX, Airport.NRT); Flight f5 = new Flight(new Plane(Airline.United, "Boeing 737"), "414", 59, new Time(6, 50), 85, Airport.LAX, Airport.SFO); System.out.println(f1.toDetailedString()); System.out.println(); System.out.println(f1.toOverviewString()); System.out.println(); System.out.println(); System.out.println(f5.toDetailedString()); System.out.println(); System.out.println(f5.toOverviewString());
  • 6. } } Solution #include #include #define MAX_NUM_SEATS (20) #define MAX_NUM_SEATS_IN_FIRST_CLASS (5) #define MAX_NUM_SEATS_IN_ECONOMY (MAX_NUM_SEATS - MAX_NUM_SEATS_IN_FIRST_CLASS) int main() { int plane[MAX_NUM_SEATS] = {0}, i=0; int nNumSeatsInFirst = 0; int nNumSeatsInEconomy = 0; int nSeatAssignmentFirstClass = 1; // start at 1; int nSeatAssignmentEconomy = MAX_NUM_SEATS_IN_FIRST_CLASS + 1; // start at 6 int choice; int nClass; int nCurrentSeatAssignment;// firstClass=1,economy=6,choice; char response[2]; char firstname[35], lastname[35]; int bPrintTicket; while( i < MAX_NUM_SEATS ) { printf(" %s %s ", "Please type 1 for "First class"","Please type 2 for"Economy""); scanf("%d", &choice); if( !( ( 1 == choice ) || ( 2 == choice ) ) ) { continue;
  • 7. } // start out assuming we will print ticket! bPrintTicket = 1; printf(" Enter first name:"); scanf("%s",firstname); printf(" Enter lastname :"); scanf("%s", lastname); nClass = choice; // store the class before doing all the logical checks /****************************************************************/ /*************** ECONOMY SECTION ***************/ /****************************************************************/ if( 2 == choice ) { // check for economy full if( nNumSeatsInEconomy >= MAX_NUM_SEATS_IN_ECONOMY ) { // economy full // check for first class (plane ) full if( nNumSeatsInFirst <= MAX_NUM_SEATS_IN_FIRST_CLASS ) { printf("The economy section is full. "); printf("would you like to sit in first class "); printf("section( Y or N)?"); scanf("%s", response); if ( toupper(response[0])=='Y') { // print ticket! bPrintTicket = 1; printf( "Your seat assignment is %d ", nSeatAssignmentFirstClass ); nCurrentSeatAssignment = nSeatAssignmentFirstClass;
  • 8. plane[nSeatAssignmentFirstClass - 1] = 1; nSeatAssignmentFirstClass++; nNumSeatsInFirst++; nClass = 1; i++; } else { // don't print ticket! bPrintTicket = 0; printf("Next flight leaves in 3 hours. "); } } else { // don't print ticket! bPrintTicket = 0; // print out that plane is full printf("Plane is full, next flight in 3 hours "); } } else { // economy is not full printf("Your seat assignment is %d ", nSeatAssignmentEconomy ); plane[(nSeatAssignmentEconomy - 1)] = 1; nCurrentSeatAssignment = nSeatAssignmentEconomy; nSeatAssignmentEconomy++; nNumSeatsInEconomy++; i++; } } // if( choice == 2 ) /****************************************************************/ /*************** FIRST CLASS SECTION ***************/
  • 9. /****************************************************************/ if( 1 == choice ) { // check for fisrt class full if( nNumSeatsInFirst >= MAX_NUM_SEATS_IN_FIRST_CLASS ) { // first class full // check for economy class (plane) full if( nNumSeatsInEconomy <= MAX_NUM_SEATS_IN_ECONOMY ) { printf("The First Class section is full. "); printf("Would you like to sit in the economy "); printf("section (Y or N)?"); scanf("%s", response); if(toupper(response[0])=='Y') { printf("Your seat assignment is %d ",nSeatAssignmentEconomy); plane[nSeatAssignmentEconomy - 1] = 1; nCurrentSeatAssignment = nSeatAssignmentEconomy; nSeatAssignmentEconomy++; nNumSeatsInEconomy++; i++; nClass = 2; } else { // don't print ticket! bPrintTicket = 0; printf("Next flight leaves in 3 hours. "); } } else { // don't print ticket!
  • 10. bPrintTicket = 0; // print out that plane is full printf("Plane is full, next flight in 3 hours "); } } else { // first is not full printf("Your seat assignment is %d ", nSeatAssignmentFirstClass ); plane[(nSeatAssignmentFirstClass - 1)] = 1; nCurrentSeatAssignment = nSeatAssignmentFirstClass; nSeatAssignmentFirstClass++; nNumSeatsInFirst++; i++; } } if( 1 == bPrintTicket ) { printf(" **************************************** "); printf(" * * "); printf(" NAME:%s, %s ",lastname,firstname); printf(" * * "); printf(" CLASS:%d ",nClass); printf(" * * "); printf(" SEAT:%d ",nCurrentSeatAssignment); printf(" * * "); printf(" "); printf(" **************************************** "); } } printf(" All the seats for this flight are sold ");