import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Plane extends JApplet
           implements ActionListener {
   JTextField input;
   JLabel prompt1, prompt2;
   JButton yesButton, noButton;
   int section, seats[], smoking;
   int nonsmoking, people;

   public void init()
   {
      input = new JTextField( 4 );
      input.addActionListener( this );
      prompt1 = new JLabel( "Please type 1 for smoking" );
      prompt2 = new JLabel( "Please type 2 for nonsmoking" );
      yesButton = new JButton( "Yes" );
      noButton = new JButton( "No" );
      yesButton.addActionListener( this );
      noButton.addActionListener( this );

      // The enabled method has not been introduced up
      // to this point in the book. It is used here to
      // disable the buttons by "graying" them.
      yesButton.setEnabled( false );
      noButton.setEnabled( false );

      seats = new int[ 11 ];
      smoking = 6;      
      nonsmoking = 1;

      Container c = getContentPane();
      c.setLayout( new FlowLayout() );
      c.add( prompt1 );
      c.add( prompt2 );
      c.add( input );
      c.add( yesButton );
      c.add( noButton );
   }

   public void actionPerformed( ActionEvent e )
   {
      if ( e.getSource() == input && people <= 10 ) {
         section = Integer.parseInt( input.getText() );
         String s = "";

         if ( section == 1 ) {

            if ( smoking <= 10 && seats[ smoking ] == 0 ) {
               s = "Smoking. Seat #" + smoking;
               seats[ smoking++ ] = 1;
               people++;
            }
            else if ( smoking > 10 && nonsmoking <= 5 ) {

               // enable buttons
               yesButton.setEnabled( true );
               noButton.setEnabled( true );

               s = "Smoking is full. Non-smoking?";
            }
            else
               s = "Next flight leaves in 3 hours.";
         }
         else if ( section == 2 ) {

            if ( seats[ nonsmoking ] == 0 && nonsmoking <= 5 ) {
               s = "Nonsmoking. Seat #" + nonsmoking;
               seats[ nonsmoking++ ] = 1;
               people++;
            }
            else if ( nonsmoking > 5 && smoking <= 10 ) {

               // enable buttons
               yesButton.setEnabled( true );
               noButton.setEnabled( true );

               s = "Nonsmoking is full. Smoking?";
            }
            else
               s = "Next flight leaves in 3 hours.";
         }
         else
            s = "Invalid input.";

         showStatus( s );         
      }
      else if ( e.getSource() == yesButton ) {

         if ( section == 1 ) {
            showStatus( "Your seat assignment is " + nonsmoking );
            seats[ nonsmoking++ ] = 1;         
         }
         else {  // section is 2
            showStatus( "Your seat assignment is " + smoking );
            seats[ smoking++ ] = 1;     
         }

         ++people;
         noButton.setEnabled( false );
         yesButton.setEnabled( false );
      }
      else if ( e.getSource() == noButton ) {
         showStatus( "Next flight leaves in 3 hours." );
         noButton.setEnabled( false );
         yesButton.setEnabled( false );
      }
   }
}

Edited 5 Years Ago by Nick Evan: n/a

Converting from Java to C++ is not just a matter of translating the syntax from 1 language to the other, but also the use of corresponding libraries. GUI libraries in C++ are not standardised and therefore there won't be a standard translation of your code. Which operating system are you working on? Which compiler and GUI library are you using?
The syntax of Java and C++ are quite similar so translating from Java to C++ is actually fairly straightforward. The reverse is not true.

i havent learn c++ please help me convert all...let me see any different can reference

And reason of the program and conversion? If you happened to study c++ and haven't learned it yet, there is only one correct answer: start to study it like you should. Others can not study for you. Also you do not give attribution of the original code, so if somebody helps you with transcoding, how he can have guaranteed that you do not take credit of other's code?

The OP is trying to cheat his way through his C++ class. He got the classic "airplane reservation" problem and doesn't want to put in any effort. So first he tried to trick us in making it and now he has found the solution in Java and wants it converted.

Sorry bud, no deal. Thread closed.

Comments
That's what I'm talkin' about! Bring those perps to justice.
This article has been dead for over six months. Start a new discussion instead.