Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Difficulty trying to run this program. On the output, I get the first method to

ID: 3628110 • Letter: D

Question

Difficulty trying to run this program. On the output, I get the first method to print however, the second method does not print. The program compiles without errors. Can you help? Tried to redo the program without plagiarism.

// Exercise 7.19: AirplaneReservationsSystem.java
// Write an application to assign seats on each flight of
// the airline's only plane with capacity: 10.
import java.util.Scanner; // imports class Scanner

public class AirplaneReservationsSystem
{

int firstClass = 0;
int economy = 5;
int choice = 0;
boolean seats[] = new boolean[ 10 ];
int section = 0;

Scanner input = new Scanner( System.in );

public void alternatives()
{
System.out.print( "Please type 1 for First Class."
+ " Please type 2 for Economy. " );
System.out.print( "Choice: " );
int choice = input.nextInt();

for( int seatingChart = 0; seatingChart < seats.length; seatingChart++ )
seats[ seatingChart ] = false;

} // end of method alternatives

public void assignSeats()
{
if( section == 1 )
{
if( firstClass < 5 )
{
seats[ firstClass ] = true;
System.out.printf( "First Class. Seat number %d", firstClass );
firstClass++;
} // end of if

else if( firstClass >=5 && economy < 10 )
{
System.out.println( "First Class is full. Would you like Economy?" );
System.out.print( "1 for Yes or 2 for No: " );
choice = input.nextInt();

if( choice == 1 )
{
economy++;
System.out.printf( "Economy. Seat number %d", economy );
}
else
System.out.print( "Next flight leaves in 3 hours");
}
else if( section == 2 )
{
if( economy < 10 )
{
seats[ economy ] = true;
System.out.printf( "Economy. Seat number %d", economy );
economy++;
} // end of if

else if( economy >=10 && firstClass < 5 )
{
System.out.print( "Economy is full. Would like First Class?" );
System.out.print( "1 for Yest or 2 for No: " );
choice = input.nextInt();

if( choice == 1 )
firstClass++;
System.out.printf( "First Class. Seat number %d", firstClass );
}
else
System.out.print( "Next flight leaves in 3 hours." );
}

}
} // end of method assignSeats

} // end of class AirlineReservationsSystem
// Exercise 7.19: AirplaneReservationsSystemTest.java
// Write an application to assign seats on each flight of
// the airline's only plane with capacity: 10.

public class AirplaneReservationsSystemTest
{
public static void main( String[] args )
{
AirplaneReservationsSystem myAirplaneReservationsSystem = new AirplaneReservationsSystem();

myAirplaneReservationsSystem.alternatives();
} // end main method
} // end of class AirplaneReservationsSystemTest

Explanation / Answer

please rate - thanks

you didn't give specifics- hope this is good

// Exercise 7.19: AirplaneReservationsSystem.java
// Write an application to assign seats on each flight of
// the airline's only plane with capacity: 10.
import java.util.Scanner; // imports class Scanner

public class AirplaneReservationsSystem
{

int firstClass = 0;
int economy = 5;
int choice = 0;
boolean seats[] = new boolean[ 10 ];
int section = 0;

Scanner input = new Scanner( System.in );
public void reservations()
{for( int seatingChart = 0; seatingChart < seats.length; seatingChart++ )
seats[ seatingChart ] = false;
while(firstClass<=5&&economy<10)
{
section=alternatives();
assignSeats();
}
System.out.println("Plane is full");

}

public int alternatives()
{
System.out.print( "Please type 1 for First Class."
+ " Please type 2 for Economy. " );
System.out.print( "Choice: " );
int choice = input.nextInt();
return choice;
} // end of method alternatives

public void assignSeats()
{
if( section == 1 )
    {
     if( firstClass < 5 )
        {
         seats[ firstClass ] = true;
         System.out.printf( "First Class. Seat number %d ", firstClass );
         firstClass++;
         } // end of if

    else if( firstClass >=5 && economy < 10 )
        {
         System.out.println( "First Class is full. Would you like Economy?" );
         System.out.print( "1 for Yes or 2 for No: " );
         choice = input.nextInt();

        if( choice == 1 )
           {
            economy++;
            System.out.printf( "Economy. Seat number %d ", economy );
           }
        else
            System.out.print( "Next flight leaves in 3 hours ");
           }
        }
else if( section == 2 )
{
if( economy < 10 )
{
seats[ economy ] = true;
System.out.printf( "Economy. Seat number %d ", economy );
economy++;
} // end of if

else if( economy >=10 && firstClass < 5 )
{
System.out.print( "Economy is full. Would like First Class?" );
System.out.print( "1 for Yest or 2 for No: " );
choice = input.nextInt();

if( choice == 1 )
firstClass++;
System.out.printf( "First Class. Seat number %d ", firstClass );
}
else
System.out.print( "Next flight leaves in 3 hours. " );
}


} // end of method assignSeats

} // end of class AirlineReservationsSystem

----------------------------------------

// Exercise 7.19: AirplaneReservationsSystemTest.java
// Write an application to assign seats on each flight of
// the airline's only plane with capacity: 10.

public class AirplaneReservationsSystemTest
{
public static void main( String[] args )
{
AirplaneReservationsSystem myAirplaneReservationsSystem = new AirplaneReservationsSystem();

myAirplaneReservationsSystem.reservations();
} // end main method
} // end of class AirplaneReservationsSystemTest

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote